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:
On 27/06/06, Daniel Berlin <dberlin@dberlin.org> wrote:
Manuel LÃpez-IbÃÃez wrote:
> 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.


But... tree is a pointer to "union tree_node" , isn't it? perhaps it is that "const tree" is not the same as " const union tree_node * " ?

(btw, thanks for taking the time to clarify my doubts...)


typedef union tree_node *tree;
void f(const tree a);

is equivalent to

void f(union tree_node * const a);

ie, it says the pointer is const so there's little point in using it.

typedef union tree_node const *const_tree;
void f(const_tree a);

*would* be meaningful, however.

--
Tristan Wibberley


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