This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why are we not using const?


Manuel LÃpez-IbÃÃez wrote:
> Dear all,
> 
> from comments in the #gcc irc channel, I understood that it is not
> advisable for gcc patches to use the const qualifier in function
> prototypes. I would like to understand why. Apart from its main
> purpose, I believed that the use of 'const' helps the compiler to
> optimise the code.


It generally doesn't, unless you apply const to the underlying type, and
not just the pointer.

IE you say you have a pointer to a constant piece of memory, not a
constant pointer to a piece of memory.

Otherwise, we generally *already* know it doesn't change, we don't need
your help :)

The only places it helps therefore are in globals, and if you enjoy
passing the address of pointers to functions.

This is the way things are in C, anyway.
In C++, with nice things like const methods, it's a different story.

--Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]