Re: [AD] pack_fwrite and const

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


In reply to Vincent Penquerc'h <vincent@xxxxxxxxxx>:
>> If a function's parameter is declared `const', then the compiler can
>> assume certain optimisations. A trivial (C++) example:
>
>Unfortunately, this is far less than one might think, mainly because
>it is legal to cast away constness. Only in trivial examples like the
>one you gave is the compiler able to generate better code. In real code
>it often has to fallback to a conservative code generation.

Yes, it is legal (though not at all recommended) to cast away const, but
when the programmer does this, s/he has to ensure that the changes made
to the variable won't have adverse effects elsewhere, otherwise you can
get some *very* strange results.

But casting away the const qualifier is bad when that qualifier is there
for a very specific reason: for instance, the data being referred to is
actually located in read-only memory, or something similar.

Bye for now,
-- 
Laurence Withers, lwithers@xxxxxxxxxx
                http://www.lwithers.demon.co.uk/

Attachment: signature.asc
Description: PGP signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/