Which is better?

Which is better?

Other urls found in this thread:

repl.it/JanU
twitter.com/AnonBabble

they aren't even the same but I think you knew that before you posted you double nigger

null is not always the same value or type as false

Delet thread and try again

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;

First checks for null, second checks for false

However if the first was if(ptr == false) I'd say the second way is better

They are the same retard. Go back to HTML dev

just save yourself from any headaches user

if(true)
{
..
}

just go with it, you will have more time to drink piƱa colladas

>They are the same retard.
Kill yourself. NULL is not the same as boolean false.

if (false) {
print("Op is not a faggot");
}

There is no boolean false in c.

There's a lot of stupid shit going on in C. That's why we don't design our languages after it.

use c++ & nullptr instead, you fuck

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).

Boolean is a useless type when the smallest memory you can address without bit fields is 8 bits.

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.

if (_.isNil(ptr)) {
/* do something */
}


Checks for null and undefined.

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)

you're actually retarded

if(isObjectEmpty(x) && !x && x == NULL && !(bool)x && (x ? x : false)) {

}

You can never be too sure...

If x is NULL won't that always return false?

>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.

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.

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).

lol

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.

Also context. Say depending on how far decleration is from use.

#define NULL (void *) 1

Because fuck your validation.

The standard guarantees that a NULL pointer compares equal to 0, even if the architecture doesn't use 0 as the NULL pointer.

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.

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.

>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.

depends on the language retard

>NULL
>Not nullptr

C

Dumb Ctard doesn't understand the point of types. Not surprising.

Why the fuck are you using C?

>having pointers in your language

Who is this cute girl?

>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) {

}

>girl

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.

Have you ever touched a pointer in your life?

Somewhere in stdlib.h...

>#define NULL 0

Not always for embedded systems. there's a reason the null macro exists, not just a synonym for 0

It's 2017 and people don't write

if (NULL == ptr) {

Nowadays compilers warn about this shit, no need to make things less readable.

you mean
#define NULL ((void *)0)

You're a fucking idiot. "!ptr" is defined as evaluating to 1 if ptr is NULL.

ptr == NULL is exactly what it is.
!ptr is ptr == false
git gud famalamdingdong

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.

...

>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.

you are fucking stupid lmao
what if I told you that true/false is just an alias/enum for 1/0

You need to get out of your dimension more.

if (ptr == nullptr)
{

}

what reasons are those?

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.

this

along with enums, right?

repl.it/JanU

#include

int main() {
bool hello = false;
bool* goodbye = &hello;

if(goodbye == NULL) {
std::cout

>C++
>NULL macro
kys

I prefer !ptr

if(!ptr)
continue;
else
return !ptr ? !ptr : !ptr;

>Which is better?
IIRC they are both defined by the C standard as being identical.

>use c++
Not even once.

If they both compile to the same opcodes then who gives a shit

!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 to
if variable:
return(None)

because it is more readable and more obvious which condition triggers the statement. explicit beats implicit every time.

nice meme. you are very stupid