I
Ike Naar
&__NULL__ can be a contant integral expression evaluating to zero, if the
implementors so want.
&__NULL__ can be a contant integral expression evaluating to zero, if the
implementors so want.
James Kuyper said:Perhaps, though I doubt that the fact that __NULL__ is a reserved word
gives an implementation permission to ignore the standard semantics of
'&', which can never appear as the first token of an expression with
integer type.
Did you mean to add more qualifiers? I believe that &x - &x is
an expression with integer type, for appropriately defined 'x'.
Perhaps, though I doubt that the fact that __NULL__ is a reserved word
gives an implementation permission to ignore the standard semantics of
Sorry for my previous post which did not contain any new text.
Something went wrong during posting.
In the meantime, James has already submitted a response
similar to what I was trying to submit:
Kaz's quoted statement about "contant integral expression" contradicts
6.6 p6 which states that an integer constant expression shall have
integer type, while &__NULL__ has type pointer-to-char.
__NULL__ being a reserved word means that demons can fly out of the
programmer's nose when it is used.
On a DeathStation 9000, &__NULL__ overwrites the partition table on your
root disk.
Kenneth Brody said:On 10/28/2011 4:13 PM, BartC wrote: [...]Anyway there's a million ways a program can silently go wrong; A, B and N
might not be zero, but how do we know they are correct?
Having a program deliberately crash is a crude way of detecting some classes
of error.
"Deliberately crash" is a bit misleading. The crash, on those systems which
do crash, is a side effect of invoking UB. It's not like the implementation
has:
if ( s1 == NULL ) CrashProgram();
Kenneth Brody said:I know of at least one system which would return zero, as the
system purposely reserves an all-bits-zero "page" of read-only
memory at address zero.
On some other system, it would return non-zero, as there was data
at address zero which would not be '\0'. (Unless "far" pointers
were being used, in which case, the byte may or may not have been
'\0'.)
However, on just about any system I use today, I would expect
the program to crash.
On a DeathStation 9000, &__NULL__ overwrites the partition table on your
root disk.
Kenneth Brody said:Does anyone know what K&R1 said about free(NULL)?
ImpalerCore said:What would you expect strcmp("", NULL) to return?
Ideally, I would love to see the behavior dependent on preprocessor
flag.
If DEBUG is defined,
Constraint violation: s2 != NULL, file example.c, line 9, function
strcmp
[crash]
If DEBUG is not defined: [crash]
[snip elaboration]
James Kuyper said:On 11/03/2011 11:00 AM, Kenneth Brody wrote:
...Note, too, that it's perfectly acceptable (as far as the C language itself
is concerned) to have NULL point to a "valid" address, as long as no valid
object can be at that address. ...
That is correct.
... For example, it would be legal (AFAIK) for
an implementation to do something like this:
extern char __NULL__;
#define NULL ((void *)(&__NULL__))
No, NULL is required to expand into a null pointer constant. A null
pointer constant is either "An integer constant expression with the
value 0, or such an expression cast to type void *," (6.3.2.3p3).
ICEs must have integer type; &__NULL__ has a pointer type. The operands
of an ICE "shall only have operands that are integer constants,
enumeration constants, character constants, sizeof expressions whose
results are integer constants, and floating constants that are the
immediate operands of casts." (6.6p6). __NULL__ qualifies as none of
those things. While "an implementation may accept other forms of
constant expressions" (6.6p10), those other forms will, by definition of
"other", not have the right form to qualify as any of the specific types
of constants specified in 6.6p6. [snip unrelated]
James Kuyper said:[snip]
However, null pointer constants are defined as involving an "integer
constant expression", a phrase whose meaning as a whole is defined in
6.6p6. [snip]
Ike Naar said:Sorry for my previous post which did not contain any new text.
Something went wrong during posting.
In the meantime, James has already submitted a response
similar to what I was trying to submit:
Kaz's quoted statement about "contant integral expression" contradicts
6.6 p6 which states that an integer constant expression shall have
integer type, while &__NULL__ has type pointer-to-char.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.