Topic : 8051 compiler - constant expressions with ANSI promotion disabled

Forum : 8051

Original Post
Post Information Post
April 24, 2007 - 4:36pm
Guest

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
b) unsigned int const code (100 * 135) evalauates to 88 = (100 * 135) MOD 256

and
c) (255 + 1) evaluates to 0 when used inline e.g

if( bucketSize < (2* (255+1) /3) * (unsigned int)cfg->inQSize ) becomes
if( bucketSize < 0 )

Questions...

1. Does Raisonance intend 'NOINTPROMOTE' to apply to constant expressions?
There are no code efficiencies to be gained by doing this.

2. If the ANSI rules are off, what are the rules?
b), c) above are truncated, but a) is not.

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

Replies
Post Information Post
+1
0
-1
April 24, 2007 - 5:21pm
Guest

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