A diagnostic "gotcha"
Chris Torek
chris at umcp-cs.UUCP
Thu Feb 13 08:30:34 AEST 1986
In article <659 at tymix.UUCP> kanner at tymix.UUCP (Herb Kanner) writes:
>A line of C code that looked like:
>
> node_mem[*dotp] = val & 0xff;
>
>produced the diagonistic "operands of + have incompatible types." The
>error was that *dotp was not of type int, and a[b] being a euphemism for
>*(a + b), it complained about the operands of addition.
At a guess, I would say that `dotp' was declared as a pointer to
an enumerated type. `char' and `short' are promoted to `int' in
addition expressions. `enum's being what they are (half in and
half out of integer space at the moment), the 4.2 and 4.3 BSD C
compilers will not allow them to be added to pointers. The ANSI
standard should clear this up.
In the meantime, a cast suffices to make the compiler accept the code:
node_mem[(int) *dotp] = val & 0xff;
---though to my mind using enumerated types as indicies is `treading
on thin ice' (I have no explanation as to why I feel this way; I
just do).
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list