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: Need C optimization help


Please forgive me for potentially silly question that may not help Mark
speedup his program. If I understand the "const" keyword, it tells the
computer that after a const variable gets its first value, that
variable's value will be unchangeable. So I wonder why our friend has
declared some const variables inside a for-loop and why those variables
appear on the left sides of the assignment operator inside that loop.
Silly question: Could Mark's computer be wasting time by trying to
change the value of a variable that already has an unchangeable value?



No, const simply asks the compiler to notify you when you write code which changes the value.

Modifying an object via a const lvalue is a constraint violation; any program that does this is not a valid C program.

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


Segher



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