casting int constants to pointers (was: switch (expression))

Guy Harris guy at gorodish.Sun.COM
Tue Jul 19 18:27:29 AEST 1988


> >[sbrk(), as well as shmop(), returns (char *)-1 on error]
> 
> Neither sbrk() nor shmop() is part of the ANSI C library.

Yes, I think we all knew that, but those were the examples the previous poster
used....

> >Unfortunately, we're stuck with the sins of the past, such as system calls
> >returning -1 even when they're returning pointers and special signal handler
> >values such as "(int (*)())1" (changed to "(void (*)...", which still
> >doesn't fix the problem in question),
> 
> In ANSI C, the values of SIG_DFL, SIG_IGN, and SIG_ERR are not specified.
> Providing them as macros does fix the problem in question.

Which problem is that?

Given any program using those macros, you can write an equivalent program that
doesn't use them by subsituting the definition of those macros for each
occurrence of them, they don't intrinsically solve the problem of providing
"unique" pointer values of a given type other than the NULL pointer of that
type.

They may make it easier for some implementations to choose techniques for
providing this value other than casting integral values other than 0 to the
pointer type in question (e.g., declaring some "special" objects of that type,
such as "void __sig_ign__(int)").  (I suspect in practice, however, that few,
if any, implementations - or, at least, few UNIX implementations - will do so,
purely because of inertia.)



More information about the Comp.std.c mailing list