This is the mail archive of the gcc-help@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: question - optimization and const


Hi Dima,

> 1) Does optimization process of g++ looks at "const"s
>     at all ?

Yes.  Some optimizations only happen with const data.

> 2) If yes, can the action of changing const arguments
>     bring to incorrect code.

Yes.

For example, if the const data is stored in ROM, or protected RAM tagged as
Read Only, the code that modifies the data will fail.

Despite that the code leaves the data in its original state.  (That is to
say, the data is logically const.)

You could represent the data this way:

struct Double10x10
{
  mutable double data[10][10];
};

And pass in:

void Foo(const Double10x10& in);

Or pass it by value on the stack (which probably defeats what I presume is
your purpose not to copy the data in the first place... and also makes the
const qualifier of far lesser relevance):

void Foo(const Double10x10 in);

HTH,
--Eljay


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