Re: WinAVR warum hier kein Warning?



Moin,

Werner Brennecke schrieb...
uint8_t i8 = 0;
uint16_t i16 = 0;
uint32_t i32 = 20000;

i16=i32;
i8=i32;

warum erzeugen die unteren 2 Zeilen eigentlich kein Warning in WinAVR obwohl
ich den
Parameter "-Wall" im gcc gesetzt habe?

Keine Ahnung, nutze den GCC nicht. Allerdings sind Warnungen ja auch nur
'kann', aber nicht 'muß'.


Wo ist mein Denkfehler?

Keiner, denn solche Zuweisungen können immer mit Genauigkeitsverlust
einhergehen. Allerdings gibt es für den 'unsigned'-Fall eine klare
Reglung im Standard bezüglich Konversion:

1 When a value with integer type is converted to another
integer type other than _Bool, if the value can be
represented by the new type, it is unchanged.

2 Otherwise, if the new type is unsigned, the value is
converted by repeatedly adding or subtracting one more
than the maximum value that can be represented in the
new type until the value is in the range of the new type.

Nach Fall 2 wird der Code jetzt so interpretiert, wenn
sizeof(i8) == sizeof(unsigned char)
und
sizeof(i16) == sizeof(unsigned short)
gilt:

i16=i32 % (USHRT_MAX+1);
i8=i32 % (UCHAR_MAX+1);


- Heinz
.



Relevant Pages

  • Re: More bit shifting issues
    ... I seem to be having yet more wierd issue with bit shifting. ... seems the following code doesnt do anything under gcc (ie it ... integer type. ...
    (comp.lang.c)
  • Re: How to store a 13 digit number in c ?
    ... maximums for the number of bits in each integer type. ... which C99 compiler do "almost" everybody use these days? ... said something about GCC not having changed in 3 years. ...
    (comp.lang.c)
  • Re: Visual Studio 2005 x64 mode.
    ... just like in GCC. ... What again are you complaining about? ... order to get 64-bit integer type one should use `long long' type: ... "Data Type Ranges" ...
    (microsoft.public.vc.language)
  • Re: 64-bit for gcc-gnat-3.3.2
    ... Andreas Almroth wrote: ... > I may be wrong here, but I don't think the Ada part of gcc supports 64 ... That is my experience when trying to compile with gcc. ... account, unless you change the Integer type to be 64 bit, or change to ...
    (comp.lang.ada)

Loading