How to use C89 with certain C99 features
Ian Lance Taylor
iant@google.com
Wed Apr 6 14:43:00 GMT 2011
Steffen Dettmer <steffen.dettmer@googlemail.com> writes:
> You cannot have const members with runtime data.
> As I understand it, the "small old" compilers may locate
> const data into ROM (or other RO memory), which makes it
> impossible to initialize it with runtime data, so again the
> problem may not be the compiler language / version, but
> properties of the equipment. If you want your code to be runable
> on such systems, you cannot use it.
In C89 or C99, a variable declared as const can not be modified after it
is created. Any initializer of such a variable may contain only const
expressions. So such a variable may be placed in read-only memory, and
gcc will in fact normally do so. (There are some cases where this can
not be done when using -fpic).
C++ is more complicated, due to constructors and the mutable storage
class specifier.
Ian
More information about the Gcc-help
mailing list