implicit cast from unsigned long to unsigned int gives no warning with -Wall (64 bits arch)

Vincent Torri vtorri@univ-evry.fr
Wed Nov 21 18:31:00 GMT 2007



On Wed, 21 Nov 2007, Tom St Denis wrote:

> Vincent Torri wrote:
>> 
>> hey,
>> 
>> I have an ubuntu 64 bits on my core 2 duo. gcc version is 4.1.2
>> 
>> I compile that code with -Wall:
>> 
>> 
>> 
>> unsigned int htonl (unsigned int i)
>> {
>>   i = 0;
>>   return 0;
>> }
>> 
>> int
>> main ()
>> {
>>   unsigned long i;
>>   unsigned int j;
>>
>>   i = 0;
>>   j = htonl (i);
>
> I want to know why you assume j = ... should give a warning but not i = 0. 
> (hint: what is the type of 0?).
>
> In C, casts are implicit.  That's how you can do things like
>
> int ch = 'a';

you can't loose data here, while a cast from a 64bits int to a 32 bits can 
loose data.

I was not precise enough : i was expecting a warning on the line where 
htonl is called

Vincent Torri



More information about the Gcc-help mailing list