www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/02/17:15:24

Date: Tue, 2 May 95 16:10:30 EDT
From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock)
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Subject: Re: Bad bug with for(-;-;-) and an enum name
Reply-To: babcock AT cfa DOT harvard DOT edu

> #include<stdio.h>
> enum{q=1,imax=256};
> main(){double x,y; int i,j,k,l,im=imax;
> printf("A: "); for(i=-im  ;i<im  ;i++) printf("%d ",i); printf("\n");
> printf("B: "); for(i=-imax;i<imax;i++) printf("%d ",i); printf("\n");}
> 
>   When this Gnu C++ program runs, loop A prints consecutive numbers on screen
> as expected, but loop B prints <<no numbers at all>>.

First guess would be that imax is interpreted as an unsigned int, messing up
the i<imax test.  I'm not sure whether it is legal for the compiler to do
this or not, but, at least in this code fragment, I don't see any reason to
use enum rather than int.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019