Which is better?
they aren't even the same but I think you knew that before you posted you double nigger
>>61462457
null is not always the same value or type as false
Delet thread and try again
>>61462457
Neither
(ptr == nullptr)
{
>having NULL in your language
first:if (ptr == nullptr) {
}
Second:Class* g_pClass = nullptr;
if (!g_pClass) {
}
Depends on the condition you actually want to use
if (!ptr)
return !!!ptr;
>>61462457
First checks for null, second checks for false
However if the first was if(ptr == false) I'd say the second way is better
>>61462507
They are the same retard. Go back to HTML dev
just save yourself from any headaches anon
if(true)
{
..
}
just go with it, you will have more time to drink piƱa colladas
>>61462726
>They are the same retard.
Kill yourself. NULL is not the same as boolean false.
if (false) {
print("Op is not a faggot");
}
>>61462801
There is no boolean false in c.
>>61463090
There's a lot of stupid shit going on in C. That's why we don't design our languages after it.
>>61462457
use c++ & nullptr instead, you fuck
>>61462457
Assuming NULL is 0, C compilers should output the same assembly code in both cases (comparing it to zero). I think the first one is more readable, but I'd go with whatever style the big projects use (e.g., Linux).
>>61463238
Boolean is a useless type when the smallest memory you can address without bit fields is 8 bits.
>>61465438
Nah man, thats a bad assumption. NULL is literally nothing while 0 is still something. OP is a fag and baited every C fag with an ambiguous example of a modern language, which C is not.
>>61462457if (_.isNil(ptr)) {
/* do something */
}
Checks for null and undefined.
>>61462457
in C, I usually end up just using the latter -- it's guaranteed to work (even if your architecture doesn't actually use address 0 for a null pointer) and is less typing and is pretty idiomatic
in fact, there's no actual reason to ever check against the NULL macro in C, unless you're on some weird embedded system where it's actually not set to zero and the compiler isn't standard
the former is required in a lot of other languages though, and recommended in C++ nowadays (well, if you replaced NULL with nullptr)
>>61465636
you're actually retarded
if(isObjectEmpty(x) && !x && x == NULL && !(bool)x && (x ? x : false)) {
}
You can never be too sure...
>>61466550
If x is NULL won't that always return false?
>>61462457
>Working with people who don't know pointers
(ptr == NULL)
>Working with people who do know about pointers
(!ptr)
When it won't significantly affect performance (which is 90% of the time), it's your responsibility as a developer to write code that is the easiest to understand for you and other developers, and communicates the program's logic best. So you should use the former.
>>61465918
why would that even matter? just use == for null checks
NULL is not guaranteed to be the same as (void *)0 so the former is objectively correct.
Holy fuck, why are there so many JS fags in here?
If you haven't written C before, you should go kill yourself.
>>61466707
Zero literal is a null pointer constant. That means that comparison to zero literal is the same as comparison to NULL, even if NULL is not (void *)0 (assuming that NULL has a compliant definition).
>>61465472
lol
>>61462507
>>61462801
>>61463238
lol, you fucking retard.
Top convention in case variable names don't make type clear.
if (!ptr) is better. I think it looks more aesthetic.
>>61467850
Also context. Say depending on how far decleration is from use.
#define NULL (void *) 1
Because fuck your validation.
>>61466707
The standard guarantees that a NULL pointer compares equal to 0, even if the architecture doesn't use 0 as the NULL pointer.
>>61468101
Is ptr even a pointer?
We haven't seen it defined.
ptr can be anything in OP's image, it could be any variable type.
>>61462457
For readability, I would prefer the former (you express, that this is a null check), however the latter is more common in C programming, so it doesn't really matter.
>>61468262
>Not believing variable names
That is what I really hate in programming. You need to proofread other people's code, because they are lazy to refactor.
>>61462457
depends on the language retard
>>61462457
>NULL
>Not nullptr
>>61465472
Dumb Ctard doesn't understand the point of types. Not surprising.
>>61468685
Why the fuck are you using C?
>>61462539
>having pointers in your language
>>61462560
Who is this cute girl?
>>61463238
>nightmares about porting a C codebase to C++
>some idiot thought it was a good idea to have 0 on the C version and NULL on the c++ version
if(p == nil)
if (!!!!!!!ptr == NULL) {
}
>>61469444
>girl
>>61469521
If it looks like a girl, walks like a girl and talks like a girl, it's a girl.
The only valid system to use in such a case is dick typing.
>>61462539
Have you ever touched a pointer in your life?
>>61462510
Somewhere in stdlib.h...
>#define NULL 0
>>61469626
Not always for embedded systems. there's a reason the null macro exists, not just a synonym for 0
>>61462457
It's 2017 and people don't writeif (NULL == ptr) {
>>61469652
Nowadays compilers warn about this shit, no need to make things less readable.
>>61469626
you mean#define NULL ((void *)0)
>>61462510
You're a fucking idiot. "!ptr" is defined as evaluating to 1 if ptr is NULL.
>>61462457
ptr == NULL is exactly what it is.
!ptr is ptr == false
git gud famalamdingdong
>>61465636
NULL is defined as being casted to zero when used in a scalar context.
Friendly reminder that C style NULL define is godawful for a bunch of reasons and if you use sepples you should use nullptr instead.
>>61469548
>>61469548
>looks like a girl
I don't know any girls that have animal ears and humongous eyes that cover more than 60% of the face.
>>61463238
you are fucking stupid lmao
what if I told you that true/false is just an alias/enum for 1/0
>>61470654
You need to get out of your dimension more.
if (ptr == nullptr)
{
}
>>61470627
what reasons are those?
>>61470744
Depending on your compiler it could just be the literal 0, and follow the assignment rules of an int rather than a pointer type
also in sepples particularly it fucks with function overloads. That's the same reason a char literal really is a char in sepples.
>>61462524
this
>>61465472
along with enums, right?
>>61462507
>>61462510
https://repl.it/JanU#include <iostream>
int main() {
bool hello = false;
bool* goodbye = &hello;
if(goodbye == NULL) {
std::cout << "Goodbye is a Null Ptr!\n";
}
if(!hello && goodbye == &hello) {
std::cout << "hello is false, goodbye points to hello!\n";
}
if(!goodbye) {
std::cout << "Goodbye is a Null Ptr!\n";
}
goodbye = NULL;
if(goodbye == NULL) {
std::cout << "Goodbye is a Null Ptr!\n";
}
if(!hello && goodbye == &hello) {
std::cout << "hello is false, goodbye points to hello!\n";
}
if(!goodbye) {
std::cout << "Goodbye is a Null Ptr!\n";
}
}
stop using raw pointers though.
>>61473103
>C++
>NULL macro
kys
>>61462457
I prefer !ptr
>>61462560if(!ptr)
continue;
else
return !ptr ? !ptr : !ptr;
>>61462457
>Which is better?
IIRC they are both defined by the C standard as being identical.
>>61463457
>use c++
Not even once.
>>61462457
If they both compile to the same opcodes then who gives a shit
>>61473743!ptr ?: return !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr ?: !ptr;
Or, in shorthand:while (!ptr) return !ptr ?: !ptr;
if variable == True:
return(None)
is superior toif variable:
return(None)
because it is more readable and more obvious which condition triggers the statement. explicit beats implicit every time.
>>61470657
nice meme. you are very stupid