[comp.lang.c] Orphaned Response

jl@exunido.UUCP (11/25/86)

>However, in SysV the shmat(2) call returns (char *) -1 in case of error.  I'll
>bet a doughnut that this is where shmaddr is coming from.
>
>Is anyone aware of any computer where this would not work as intended
>(thus, couldn't support full SysV)?  It could be argued that NULL (i.e., 0,
>with its already agreed-upon special-caseness) would have been better (more
>portable?) but it's too late now and I've never heard where it hurt anyone
>either.

It does hurt someone. On a BS2000 machine and probably on other
machines with IBM/370-architectures you get real problems when
you want to use -1 as a pointer. These architectures have 32-Bit
words, so -1 ist represented as 0xFFFFFFFF. Depending on the
current addressing mode, only the rightmost 24 or 31 bits are
used for pointers. Conversion from integer to pointer is done
with an instruction that sets the unused leftmost bits to zero.
So -1 interpreted as a pointer is either 0x00FFFFFF or 0x7FFFFFFF.
What shall the compiler generate for (char *)-1 ???

We have the same problem with the signal function which must
return a -1 on error according to SysV. Our solution is, as proposed
by the ANSI-draft, the introduction of a preprocessor macro
    #define SIG_ERR (int (*)()) 1
in <signal.h>. The expression (int (*)())(-1) would be flagged
by the compiler as an error (addressmode dependent type cast).
Programs declaring signal as a function returning int will never
get an error indication.

It would help very much, if the SysV Interface Definition would
also use symbolic names in the future instead of forcing the
programmer to use unportable constructions like (char *)-1.

Joachim Linnenberg   (jl@unido.uucp)

mccaugh@sunb0.cs.uiuc.edu (05/03/90)

 Where is '&' defined to be an arithmetic operator? Isn't it a bit-manipulation
 operator -- which thus has the same precedence as logical operators, such as
 '&&' -- and is thus of lower precedence than the relational operator '==',
 hence the necessity for parentheses.

sad@bucc2.UUCP (05/04/90)

Thank you Kaleb and others who helped.  I should have made my question
more specific.  The problem has been solved.
 
Shrijay Dalal
sad@cc2.bradley.edu