lkml.org 
[lkml]   [2000]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.082 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site