Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] [Bug target/35634] New: [avr] result of char promotion comes out of CHAR_MIN/MAX [RSS Feed]

#1 March 19, 2008 13:19:06

Paulo M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] [Bug target/35634] New: [avr] result of char promotion comes out of CHAR_MIN/MAX


Dmitry K. wrote:
void foo (int i)
{
static int n;
if (i < CHAR_MIN || i > CHAR_MAX)
abort ();
if (++n > 1000)
exit (0);
}

int main ()
{
char c;
for (c = 0; ; c++) foo (c);
}Is this strictly wrong, from the C definition point of view?I know that signed overflow is "undefined". How does this test caseinteracts with -fwrapv and -fno-strict-overflow?For those unaware of signed overflow issues, there is a nice sum up here:http://www.airs.com/blog/archives/120I know that turning "undefined" into an "out of range" result is ugly,but so is signed overflow....--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"...so she told me it was either her or the ham radio, over."


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 March 19, 2008 23:43:16

Dmitry K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] [Bug target/35634] New: [avr] result of char promotion comes out of CHAR_MIN/MAX


On Wednesday 19 March 2008 22:17, Paulo Marques wrote:
> Is this strictly wrong, from the C definition point of view?
>
> I know that signed overflow is "undefined". How does this test case
> interacts with -fwrapv and -fno-strict-overflow?
>
> For those unaware of signed overflow issues, there is a nice sum up here:
>
>http://www.airs.com/blog/archives/120>
> I know that turning "undefined" into an "out of range" result is ugly,
> but so is signed overflow....

Thanks, I will read this article, very interesting.

Now I can not understand, why the Standart permits
'undefined behavior' with ordinary overflow, like
result of usage uninitialized pointer for writing.
In any case the Standart does not charge to force
the 'undefined behavior'.

Regards,
Dmitry.



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] [Bug target/35634] New: [avr] result of char promotion comes out of CHAR_MIN/MAX [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support