Linked by Eugenia Loli-Queru on Mon 14th Nov 2005 06:11 UTC
Linux Making effective use of shared memory in high-level languages such as C++ is not straightforward, but it is possible to overcome the inherent difficulties. This article describes, and includes sample code for, two C++ design patterns that use shared memory on Linux in interesting ways and open the door for more efficient interprocess communication.
Thread beginning with comment 59949
To read all comments associated with this story, please click here.
Weird Codingstyle
by anda_skoa on Mon 14th Nov 2005 10:39 UTC
anda_skoa
Member since:
2005-07-07

I have seen quite some possibilities to check for a nullpointer, like:

if (!pointer)
if (pointer != NULL)
if (pointer != 0)

but this is the the first time I saw someone check 0 against the the pointer:

if (0 != pointer)

:)

RE: Weird Codingstyle
by enar on Mon 14th Nov 2005 11:12 in reply to "Weird Codingstyle"
enar Member since:
2005-11-14

It doesn't matter in this case, but if you want to write:

if (pointer == 0)

but make a mistake and type:

if (pointer = 0)

It will compile without any errors.

if (0 = pointer)

will give an error.

Reply Parent Bookmark Score: 4

RE[2]: Weird Codingstyle
by anda_skoa on Mon 14th Nov 2005 11:42 in reply to "RE: Weird Codingstyle"
anda_skoa Member since:
2005-07-07

Ah, true, the other style would just give a warning, which can be overlooked.

It's still the first time I saw it.

Reply Parent Bookmark Score: 1

RE: Weird Codingstyle
by ma_d on Mon 14th Nov 2005 19:48 in reply to "Weird Codingstyle"
ma_d Member since:
2005-06-29

That's because, TMK, NULL is not guaranteed to be zero in the ansi c standard. But there's a lot of code that does it, and it always seems to be anyway.

NULL is guaranteed to be false though.

Reply Parent Bookmark Score: 1

RE[2]: Weird Codingstyle
by japail on Mon 14th Nov 2005 20:17 in reply to "RE: Weird Codingstyle"
japail Member since:
2005-06-30

He was referring to that particular usage of the commutativity of pointer equality. The C++ standard specifically defines 0 as the null pointer constant. So does the C99 standard IIRC.

Reply Parent Bookmark Score: 1