We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I declare a variable unsigned char bdata Kde in a.c.
[in file a.c] unsigned char bdata Kde;
[in file b.c] #include <stdio.h> ..... extern unsigned char bdata Kde; sbit testbit=Kde^1; void main(void) {......}
How hard would it be to allow the compiler to finish the job of comparing two constant expressions? That is not a simple question. You see, the ANSI standard from Section 6.6 states the following: "A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be." So, a C Compiler may evaluate constant expressions at compile-time rather than at run-time. This is the choice of the compiler developer. It is not an optimization. Evaluating constant expressions at compile-time generates tighter code. There is no difference at compile-time or at run-time between (int) 1+2 and (int) 3. Both have the same value. The Keil compiler DOES evaluate constant expressions at compile-time. I do not know of a good quality compiler that doesn't. The Keil compiler DOES NOT generate code with constants evaluated explicitly at run-time. As stated previously, this is not an optimization. It is an allowed and oft-used part of the ANSI specification. I'm certain there are plenty of compilers that generate explicit code for each operation (constant or not, unused or not). But, I would not use them for my applications where speed and code size were important. Using the assembler listing generated by the compiler is a great way to help you learn the assembly language or even to help you help the compiler generate better code. But, it is not necessarily the best way to help you validate the meaning of your code. That is best done by a utility like PC-LINT (see http://www.keil.com/pclint/ ) which checks the syntax AND SYMANTECS of the program. Jon
Jon, That is very interesting, but I think you are a little bit in denial about what level 0 is doing. It's discarding big chunks of code if it chooses to do so. I don't see that that can be considered anything but optimization. Robert
if (count = 5) { count = 1; } if (1 == 1) { count = 2; }
if (count = 5)
if (1 == 1)