Re: question - optimization and const

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux