Re: ISSUE #?? Proposal: const attribute for input params


Subject: Re: ISSUE #?? Proposal: const attribute for input params
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Thu Dec 05 2002 - 09:27:44 PST


> From michael.rohleder@motorola.com Wed Dec 4 05:43:10 2002
>
> Hi Kevin,
>
> I am amazed that you say this. Yes, "const" has no impact on linking in C,
> but I am far away from naming it therefore syntactic sugar.
> And in case of C++ it is part of the name mangling and therefore has even
> impact on linking!
>
> -Michael

If "const" was actually part of C++ name mangling it would be quite happy since
it would be another reason for using C++ instead of C. Unfortunately it isn't
(I tried it out before the last e-mail):

 void foo(int bar);

and

 void foo(const int bar);

are considered the same wrt linking. The return type is not considered either, so

 int foo(int bar);

is also the same.

NB: even if an argument is declared "const", it is only advisory, you can cast
away the const (that's why it's syntactic sugar).

Kev.

> Kevin Cameron x3251 wrote:
>
> > "const" is syntactic sugar in C (and C++), it has no impact on linking. While I agree that it is good
> > to put it in example mappings in the LRM, there is no way to force users use "const" in their C code.
> >
> > Kev.



This archive was generated by hypermail 2b28 : Thu Dec 05 2002 - 09:28:33 PST