delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/03/29/20:32:42

From: Michael Castle <mcastle AT umr DOT edu>
Subject: Re: Sizeof bug???
To: mitnits AT bgumail DOT bgu DOT ac DOT il (Roman Mitnitski)
Date: Tue, 29 Mar 1994 19:15:39 -0600 (CST)
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

>  Hi
> Please, look at the following chunk of code,
> and compilation results, and tell me, can I ignore
> the warning,and must there be a worning at all???
> main()
> {
> long UR=1;
> if (sizeof(long)>4)
>  {
>   UR=UR<<32;
>  }
> 
> }
> here's the compilation output:
> bug.c: In function `main':
> bug.c:6: warning: left shift count >= width of type

I take it you are NOT using -O?  This code *should* optimize out because:

sizeof(long)=4, therefore the conditional will ALWAYS be false, and NEVER
execute.... however, if you're not using -O, gcc probably won't look for
such dead code.

Better would be:

#define 32BITS

#ifdef 32BITS
  UR=UR<<32;
#endif


damn shame you can't do   #ifdef sizeof(long)>4 .... #endif....
but it's not supported  *sigh*

- Raw text -


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