This is growing severely off-topic, but...

Andy Isaacson wrote:

> 
> (4)
>     dpy = XOpenDisplay('\0');
> 
> is pretty questionable.  I was going to say that the compiler should
> warn you in this case, but apparently this gets away with being legal
> due to the "sizeof('c')==sizeof(int)" clause.
> 

> It seems likely that there could be systems where this example would
> fail _if sizeof('c') were 1_, but since sizeof('c')==sizeof(int), it's
> unlikely that there could be a system perverse enough to make it fail.
> 


Not at all. Standard C allows implicit conversion between any numeric 
types in an assignment. There is nothing wrong with saying 'foobar(c)' 
where c is of type 'char' and foobar() is declared to have an argument 
of type 'int'. Compilers usually provides a warning when an implicit 
integer-to-integer conversion can cause loss of information, but not 
otherwise.

However, that discussion is irreleveant since we're talking about a 
conversion from 'int' to 'char *' here (standard C specifies the type of 
a character constant as 'int'), or possibly a conversion from 'int' to 
'int' if the arguments to XOpenDisplay() have not been declared.

A conversion from a numeric type to a pointer type is unspecified in 
ANSI C, and this is where there might be a problem. However, the case of 
NULL == 0 == '\0' is so common that this would probably work just fine 
on just about any platform. In fact, C++ and possibly also C89 and C99 
_requires_ that NULL == 0 == '\0', and allows implicit conversion 
between any numeric and pointer type in an assignment where the 
initializer is a constant 0, NULL, or '\0'.

Not that I would ever write XOpenDisplay('\0'), which is utterly 
confusing :-)

-- 
Christer Palm

_______________________________________________
Xpert mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/xpert

Reply via email to