Re: "Using plain integer as NULL pointer" false positive for zero struct initializer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 9, 2019 at 4:22 PM Bernd Petrovitsch
<bernd@xxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi all!
>
> Not that I'm defending C++ in anyway (and sorry for somewhat off-topic):
>
> On 10/01/2019 00:14, Linus Torvalds wrote:
> [...]
> > And yes, I realize that the C++ people completely screwed up, and
> > originally doubled down on the old K&R C model of "NULL must be 0". It
>
> Yup, because they would have to type-cast "(void*)0" everywhere ...

No they really wouldn't.

That was always a completely bogus argument.

It's noit "0" that is NULL, it's "((void *)0)".

If C++ had gotten that _simple_ thing right, they'd not have had the
problems that they did.

There were a lot of C++ people who argued like you did, from ignorance
and stuipidity.

Then, decades later, when they finally realized they were wrong, they
had spent so much time arguing that "((void *)0)" couldn't just be
NULL, that they clearly were too embarrassed to admit that they had
been wrong all this time, so they made up a new "better" model:

> They finally fixed it with the "nullptr" symbol (and "nullptr_t" type of
> it - which makes no sense in a pure C world).

Absolutely. There were a _lot_ of C++ people who couldn't just admit
that "((void *)0)" would have been a perfectly valid way to spell
"nullptr", so they made a whole new keyword instead.


> ----  snip  ----
> #define nullptr (void*)0
> ----  snip  ----
> in C, use it instead of "NULL" and that's it totally pure clean C since
> K&R;-)

No, K&R C didn't have "void" or "void *".

But

   #define NULL ((void *)0)

has been valid C since ANSI C, and the C++ people should just have
accepted that as the spelling for "nullptr" too.

Note that it's the whole *cast* that is the NULL pointer. The above is
not "integer cast to 'void *'". No, it _is_ NULL inside the compiler
(because NULL literally has special meaning even in C, even if the
special meaning is less than the special meaning in C++).

So my point is that it's "nullptr" that is made up silliness. But it's
made up silliness because of politics, and because a lot of C++ people
had trouble admitting that the ANSI C "let's just accept a cast to
'void *'" was perfectly fine.

Some people got hung up about the "cast to 'void *'". That's not what
makes it a NULL pointer, and in C++ that special construct of "cast 0
to void *" could easily just had the type 'nullptr_t'.

Really. Exactly the same way that K&R C (and then C++) gave special
semantics to the (inferior) "#define NULL 0", and magically turned
that *inferior* model for NULL into nullptr.

But I also believe that a lof of C++ people had argued themselves into
a corner where admitting that simply wasn't possible - because it
would have involved admitting that they did some really stupid things
for decades.

Thus the syntactic sugar of calling it "nullptr", allowing some people
to claim they were right all along, when they were just being
incredibly stupid.

             Linus



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux