Hi, I have this code:
void main(void) { data unsigned char a = 0; data unsigned char b = 0; data unsigned int c = 1000;
b = c;
while(1) { a+= 1; } }
And it compiles with no errors or warnings. Why is this? Why does it not raise an error because the 16-bit value c is being stored in the 8-bit value b? The Intpromote is turned off, so that is not it.
Yours, confused.
Robbie Martin.
Thank you for the comments that have appeared. I had to ask this question on behalf of a team that I support (really), and the answers have given me a better insight into the C standard. The question was raised because we have a static code analyser which did raise a warning, whereas the compiler didn't.
I will pass these responses back to the engineer who raised the original query.
Robbie.
"we have a static code analyser which did raise a warning, whereas the compiler didn't"
Yes - that is precisely the reason why you have a static code analyser!
This is why Keil pushes PC-Lint on their website:
http://www.keil.com/pclint/
Keil has pre-made PC-Lint configuration files for all of their compilers.
This 'what if' case is a perfect role for code analysis software, not a compiler.
View all questions in Keil forum