[comp.std.c] sizeof

diamond@csl.sony.co.jp (Norman Diamond) (11/16/89)

According to section 3.2.2.3, page 38, an integral constant expression
with the value 0, or such an expression cast to type void *, is a null
pointer constant.  SUCH AN EXPRESSION CAST TO TYPE rehash * IS NOT CITED
IN THIS MANNER.  Section 3.3.4 says that the result has the named type,
i.e. rehash *.  Therefore the semantics of -> select a member of the
pointed-to type, and sizeof takes its size.

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".

gwyn@smoke.BRL.MIL (Doug Gwyn) (11/18/89)

In article <11138@riks.csl.sony.co.jp> diamond@ws.sony.junet (Norman Diamond) writes:
>Section 3.3.4 says that the result has the named type, i.e. rehash *.
>Therefore the semantics of -> select a member of the pointed-to type,
>and sizeof takes its size.

This argument was already made and I disagreed before too.
My argument is that a null pointer does not point to anything.
The only open issue I know of here is whether a compiler is
obliged to accept this construct, obliged to diagnose it, or
free to randomly decide what to do about it.  I wouldn't
recommend its use in portable programs.

diamond@csl.sony.co.jp (Norman Diamond) (11/20/89)

In article <11628@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <11138@riks.csl.sony.co.jp> diamond@ws.sony.junet (Norman Diamond) writes:
>>Section 3.3.4 says that the result has the named type, i.e. rehash *.
>>Therefore the semantics of -> select a member of the pointed-to type,
>>and sizeof takes its size.
>
>This argument was already made and I disagreed before too.
>My argument is that a null pointer does not point to anything.

In the part of my posting which you deleted, I pointed out where the
standard deliberately does not define a cast null pointer to be a
null pointer constant, unless the cast is to void *.  Therefore the
compiler cannot take advantage at compile time of knowing that this
is a null pointer; it has to wait until execution time (or at least
it has to appear that way).  Execution-time null pointers do in fact
have a type which is known at compile-time.

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".

gwyn@smoke.BRL.MIL (Doug Gwyn) (11/22/89)

In article <11146@riks.csl.sony.co.jp> diamond@ws.sony.junet (Norman Diamond) writes:
>In the part of my posting which you deleted, I pointed out where the
>standard deliberately does not define a cast null pointer to be a
>null pointer constant, unless the cast is to void *.

Which has nothing to do with it.  "Null pointer constant" has technical
uses within the standard, but both null pointer constants AND other
kinds of null pointers don't point to anything.

>Therefore the compiler cannot take advantage at compile time of knowing
>that this is a null pointer; ...

Your argument supports the position that conforming implementations are
not REQUIRED to diagnose ((foo*)0)->bar, but compilers that are able to
recognize that situation, so far as I can determine, MAY diagnose it at
compile time as a semantic violation, in which case it would be folly to
use such a construct in code intended to be portable.

As I've said before, I think this deserves an official "interpretation"
ruling.