Forum : 8051
Post Information | Post |
---|---|
April 24, 2007 - 4:36pm
|
I recently disabled ANSI-style promotion of bytes to integers ('NOINTPROMOTE' ) and got some unexepected results with constant expressions. i.e expressions which evaluate to a constant which can be used inline in a C-code line or included in a ROM table. Examples from my code are: a) unsigned int const code (100 * 33) evaluates to 3300 and if( bucketSize < (2* (255+1) /3) * (unsigned int)cfg->inQSize ) becomes Questions... 1. Does Raisonance intend 'NOINTPROMOTE' to apply to constant expressions? 2. If the ANSI rules are off, what are the rules? 3. From 1. 2. above, do the behaviours in a).. c) reflect the intended compiler design, or are one or more of them bugs? There's little information on this in the RC-51 manual; suggest adding some. regards Steven Pruzina |
When the NOINTPROMOTE mode is set, the bytes types (char and unsigned char) are considered as arithmetic types. It means that no (unary) conversion will be applied.
For the constant expressions:
A general ANSI rule for the constants is that the assumed "default type" would be the smallest arithmetic type that "accepts" the encoding of the value. Therefore, when NOINTPROMOTE is set, 10 will be considered as "signed char" and "200" as "unsigned char" (exactely as 5000 is considered as being an int, and 40000 an unsigned short...).
We recommend NOT to use NOINTPROMOTE (because the code will NOT be portable, and could be far from the "standard" expectation).
Francis