Messages in this thread | | | Date | Sun, 27 Feb 2000 22:24:39 +0100 | From | Jamie Lokier <> | Subject | Re: Performance tweaks |
| |
D. Hugh Redelmeier wrote (about C): > If you define a variable to be const, it must not be changed by the > program. If, however, you have a pointer-to-const, it is possible > that the object pointed to may change due to other parts of the > program having non-const access. > > In other words, a pointer-to-const can point to something that isn't > const. But something that is const must not be changed. > > So, in the quoted example, gcc could assume (and even enforce) that > the variable isn't changed during its lifetime.
You are right. I just tried some examples with GCC 2.95.1 using C and C++, and they both inline the value of a const int, if it is defined.
I am fairly confident that when I read the first edition of Stroustrup's book, the use of "const int" to declare constants was touted as a C++ feature, as a key difference from C which required preprocessor macros to get equivalent results.
So I'm puzzled.
-- Jamie
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |