Ultrix CC bug?
Bj|rn Larsson
bl at infovax.UUCP
Sat Sep 16 01:03:08 AEST 1989
Hello netters,
yesterday I came upon a strange behaviour in Ultrix 'C'. The following
test program causes cc to complain about the left-hand side of the marked
expression.
main()
{
short *p;
tst(p);
}
tst (p)
short *p;
{
long l;
l = *((long *) p)++; /* <<< Here! */
}
In my view,
p is a pointer to short,
(long *) p is a pointer to long,
((long *) p) is also a pointer to long,
((long *) p)++ increments the above *long* pointer,
*((long *) p) is the long pointed to,
thus
*((long *) p)++ has the value of the *long* pointed
to by p, and the *long* pointer is
set to point to the next long (i.e.
if sizeof (long)== 2*sizeof(short)
then p will be incremented by two,
counted in short's).
Any objections? I could add that both Turbo C, MicroSoft C, and the
MicroTek C 68000 cross-compiler compile this as I believe 'correctly'.
And this is no problem, I fixed it at another place - but it's inte-
resting to hear what yous C compilers do...
Bjorn
--
====================== InfoVox = Speech Technology =======================
Bjorn Larsson, INFOVOX AB : ...seismo!mcvax!kth!sunic!infovax!bl
Box 2503 : bl at infovox.se
S-171 02 Solna, Sweden : Phone (+46) 8 735 80 90
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list