Subject: Re: const'ness vs reality
From: Kevin Cameron (Kevin.Cameron@nsc.com)
Date: Wed Dec 11 2002 - 09:28:53 PST
Joao.Geada@synopsys.com wrote:
> Please everybody, lets be very careful in distinguishing between language
> conveniences vs language capabilities/rules.
> Yes, C and C++ (and numerous other languages) permit the user to mark some
> arguments as being 'const'. This is a useful indicator to the users and
> implementors of such functions about the interface expectations.
>
> HOWEVER, please do NOT confuse this convenience and extra compile time checking
> as meaning that it is forbidden for a programmer to make changes to such a variable.
> There is *no* such restriction in either language (regardless of whether the
> function name is annotated with 'const'ness attributes for the linker). Please
> recall that both C and C++ give programmers the ability to cast away the 'const'ness
> No sufficiently useful programming language can *stop* a programmer from writing buggy
> or incorrect code.
>
> My point is as follows: putting the const attribute in the prototypes for external
> functions is desirable, particularly so if the prototypes are automatically
> created by the SystemVerilog compiler. This does *not* prevent a user from
> writing to input arguments, but for users attempting to write valid code this
> would be helpful for ensuring that they are following the relevant rules.
>
> Joao
Well said.
So far the only compiler that we know of that differentiates on "const" is Sun's
C++ compiler.
Kev.
-- National Semiconductor, Tel: (408) 721 3251 2900 Semiconductor Drive, Mail Stop D3-500, Santa Clara, CA 95052-8090
This archive was generated by hypermail 2b28 : Wed Dec 11 2002 - 09:28:53 PST