C Compiler Bug

keenan at inmet.UUCP keenan at inmet.UUCP
Wed May 29 08:43:00 AEST 1985



Here is a small program that demonstrates what I think is a bug in the
BSD2.9 C compiler. I guess its not appropriate to use a long as the
index to an array, but it should just be cast to an integer, and not
affect the postdecrement. Instead the decrement treats the variable as
an integer.  The results are also presented. Is this a bug, or is my
code just incorrect?

#include <stdio.h>
int arr[100];
int x;
long p_end;
main()
{
  printf("Autodecrement inside array reference\n");
  p_end = 0l;
  printf("before %ld\n", p_end);
  x = arr[p_end--];
  printf("after %ld\n", p_end);
}

++++++++++++++++++++++++++ OUTPUT +++++++++++++++++++++++++
Autodecrement inside array reference
before 0
after 65535

--keenan ross		UUCP:     {bellcore,ihnp4}!inmet!keenan
 Intermetrics, Inc.	INTERNET: ima!inmet!keenan at CCA-UNIX.ARPA
 733 Concord Ave.
 Cambridge, MA  02138	PHONE:    (617) 661-1840



More information about the Comp.bugs.2bsd mailing list