const + optimizations [WAS: Need C optimization help]

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

 



* Segher Boessenkool <segher@xxxxxxxxxxxxxxxxxxx> wrote:
 
> Modifying an object via a const lvalue is a constraint violation; any
> program that does this is not a valid C program.

Is the compiler able to use that for optimizations (eg. hold
const variables in registers, etc) ?

BTW: in java (AFAIK) there's a lot more room for such optimizations,
eg. somehing like:

    ...
    String static final prefix = "/foo/";
    ...

    String foo = prefix+"bar";
    System.out.println(foo);

    could be optimized to:

    System.out.println("/foo/bar");
    

> Modifying a const object via a non-const lvalue is undefined behaviour.

Is there a flag to forbid that ?


cu
-- 
----------------------------------------------------------------------
 Enrico Weigelt, metux IT service -- http://www.metux.de/

 phone:  +49 36207 519931  email: weigelt@xxxxxxxx
 mobile: +49 151 27565287  icq:   210169427         skype: nekrad666
----------------------------------------------------------------------
 Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme
----------------------------------------------------------------------


[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