Integer overflow in generated C code for AVR

26 views
Skip to first unread message

Ralf Ebert

unread,
Feb 1, 2022, 4:23:47 AM2/1/22
to YAKINDU User
Hi,

I'm running generated C code on an AVR microcontroller.

At one point in the statemachine I need an "after 120 s". This is translated into the following code: 
statechart_set_timer(handle, (sc_eventid) &(handle->timeEvents.statechart_eventname_raised) , (120 * 1000), bool_false);

The problem is the (120 * 1000). On AVR this is an overflow, as any integer is 8 bit by default and the result of the calculation doesn't fit an 8-bit int. The onlx fix in the code is to suffix one of the numbers with an l (lower case L) to tell the compiler to convert it to something larger, which works because the result of the calculation is then stored in an sc_integer which is 32 bit.
If there's an other solution that doesn't involve the generated code, I'd be happy to use it. To my knowledge there isn't which is why I consider this a bug. The solution would be an option to suffix numbers in generated code with an l. (Adding the l in the statemachine results in a syntax error.)

Any solution?

Thanks

Ralf
Reply all
Reply to author
Forward
Message has been deleted
0 new messages