delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/03/29/19:31:14

Subject: Re: Sizeof bug???
To: Roman Mitnitski <mitnits AT bgumail DOT bgu DOT ac DOT il>
Date: Tue, 29 Mar 94 23:33:26 EST
From: Angelo Ferrigno <aferrign AT iisst3 DOT italy DOT NCR DOT COM>
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
> 
>  But according to the programm, it must be Ok.
> 
> Thanx in advance.
>  Roman
> 

Roman, even if I can, more or less, figure out the meaning of your test, I
must declare all my simpathy to the poor compiler ( which, after all, is
simply a mechanic translator from a buggy high-level program to a buggy
machine code program :): the compiler will SEE the shift statement for any
length of longs, so, if your machine has longs which are just 32 bits, it's
correct in stating that left shifting a long so much wouldn't make much sense
(I know of better methods to generate zeroes :).

Indeed, apart from jokes, this raises a problem which may be of some interest,
and this is the only reason I post this answer to the mailing list and not
directly to you: your code above could be written as

#if sizeof(long) > 4
   UR=UR<<32;
#endif

which conveys more clearly your intent.

Unfortunately, this is not possible, since you can't use the sizeof operator
in preprocessor directives. While I am aware of the difficulties that would
arise if one should try to implement a full-featured sizeof operator in the
preprocessor ( which would imply that the preprocessor wouldn't be just a
preprocessor, it should be able to understand the FULL syntax of C
declarations), I am pretty sure that implementing such a feature for the
builtin types (including pointers to and arrays of builtin  types) would be
a relatively simple task. GCC already introduces some exensions to ANSI C; I
don't think one (useful) more would disrupt the world: what about passing this
to FSF people?

Just thrown on the table...
-- 
+ Angelo Ferrigno                  + Phone : +39 2 58160.316               +
+ AT&T GIS Italy - WWIS            + Fax   : +39 2 58160.291               +
+ V.le Cassala, 22                 + E-Mail: Angelo DOT Ferrigno AT Italy DOT NCR DOT COM +
+ 20143  Milano  MI  (Italy)       + VP phone: 326.4316   VP fax: 326.4291 +

- Raw text -


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