This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compilation problem for constant variable

Dear all,

in my program i declared some variable as constant. After compilation this program gives me some problem related to above declare variable.

Moment i remove constant from those variable my program start working correctly.

I am inital stage of debugging. Please suggest area where i need to see to solve problem.

Regards..

Yogesh

Parents Reply Children
  • Yes, but it is quite easy to take the address of a const variable and send into a library function that drops the const (more than one library function have had the problem that they have taken a pointer to a const variable as input parameter, and returned a pointer to a non-const variable.

    It is also much too common that people make type casts to avoid signed/unsigned warnings, and at the same time looses extra attributes, such as const.

    Erik: A const variable may sound a bit strange, but since the value is actually having a memory address it is completely different from a numeric literal constant or an enumerated value or a #defined value. In a number of environments, const variables are not stored in write-protected memory, so the application may add a typecast and then use it as a normal variable.

  • The term "variable" is not really a 'C' thing - it is not mentioned in the 'C' standard - the term used is "identifier"

    This avoids the contradictory term "constant variable".

  • No, an identifier is not the same thing as a variable, since an identifier is a superset that includes functions, data types etc.

  • "an identifier is not the same thing as a variable"

    True; it would need to be specifically a data identifier - but 'C' still doesn't officially use the term "variable", as in some other languages (eg, BASIC).