Translating C const

Simon s.d.hammett at gmail.com
Wed May 16 10:55:11 PDT 2012


On 16/05/2012 09:24, Jacob Carlborg wrote:
> On 2012-05-16 09:00, Jonathan M Davis wrote:
>
>> Probably true. But also, if you're talking about a const pointer to a
>> mutable
>> value, the constness of the pointer is actually irrelevant to the
>> caller. The
>> pointer will be copied when the function is called, so it doesn't
>> matter on
>> whit whether the pointer itself is const or not. What matters is whether
>> what's being pointed to is const or not. So, if you have a function which
>> takes a const pointer to a non-const value, then that's essentially
>> identical
>> to one that takes a non-const pointer to a non-const value as far as the
>> declarations go - and for declaring extern(C) functions for use in D,
>> that's
>> generally all you care about.
>>
>> - Jonathan M Davis
>
> Ok I see, thanks. Is that true for fields in structs and global
> variables as well?
>

Yes. const pointer in c++ is some times used as short hand for saying 
that the pointer is not an array. i.e. you don't intend to increment the 
pointer or index through it.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list