Re: NULL with representation other then all bits 0



On 2006-01-28, Jack Klein <jackklein@xxxxxxxxxxx> wrote:
> On Sat, 28 Jan 2006 13:48:49 +0000 (UTC), "Vladimir S. Oka"
> <novine@xxxxxxxxxxxxxxx> wrote in comp.lang.c:
>
>> yossi.kreinin@xxxxxxxxx wrote:
>> > - AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work
>> > just like `void* p=NULL'. Is this correct?
>>
>> Yes and no. Yes, if you're compiler writer, and on your implementation
>> NULL pointer representation is 0x10000, so you defined it thus in the
>> standard header files. No, if you're trying to re-define NULL in your
>> own C program. The part of your sentence after `since` is irrelevant in
>> this context (but true).
>
> No, even if you are a compiler writer, you cannot define the macro
> NULL as something like (void *)0x10000. Not if you want your compiler
> to conform to the C language standard.
>
> The macro NULL is required by the standard to be an
> implementation-defined null pointer constant, and the meaning of "null
> pointer constant" is precisely defined by the standard:
>
> "An integer constant expression with the value 0, or such an
> expression cast to type void *, is called a null pointer constant."
>
> The expression (void *)0x10000 is neither of the two allowed forms.

I think you have a funny definition of "implementation-defined".
.



Relevant Pages

  • Re: What is a null pointer constant?
    ... >> We have, because of a simple oversight, an standard that says 0 ... are inherited by the parenthesized expression; being a null pointer ... I think it's quite obvious that this is an oversight ... treating 0) as a null pointer constant anyway, ...
    (comp.std.c)
  • Re: NULL in variadic function calls
    ... > The statement is vague enough such that a header file could define ... No. _Any_ constant integral expression acts as the null pointer ... is a perfectly valid null pointer constant. ... This was even quoted directly from the Standard (a section ...
    (comp.unix.programmer)
  • Re: [PATCH] spi
    ... > That's not a guaranteed equivalence in the C standard. ... That does not change the fact that the source-code fragment "NULL" is ... which expands to an implementation-defined null pointer constant... ... expression cast to type void *, is called a null pointer constant. ...
    (Linux-Kernel)
  • Re: NULL with representation other then all bits 0
    ... > NULL pointer representation is 0x10000, so you defined it thus in the ... No, even if you are a compiler writer, you cannot define the macro ... to conform to the C language standard. ... implementation-defined null pointer constant, ...
    (comp.lang.c)
  • Re: NULL with representation other then all bits 0
    ... Yes, if you're compiler writer, and on your implementation ... the phrase "implementation-defined null pointer ... behavior of any strictly conforming program. ... But since 0 is already a perfectly portable null pointer constant, ...
    (comp.lang.c)