This is the mail archive of the
mailing list for the GCC project.
Re: PATCH COMMITTED: EXPORTED_CONST
Jay Foad <firstname.lastname@example.org> writes:
>> +/* This is used to declare a const variable which should be visible
>> + outside of the current compilation unit. Use it as
>> + EXPORTED_CONST int i = 1;
>> + This is because the semantics of const are different in C and C++.
>> + "extern const" is permitted in C but it looks strange, and gcc
>> + warns about it when -Wc++-compat is not used. */
> You can't use this for variables of pointer type, can you, because
> EXPORTED_CONST char *p = ...;
> will give you a pointer to const char, not a const pointer to char. Is
> that not a problem in practice?
No. gcc has only a few exported const variables, and they are all
arrays, not pointers. You can see all the uses in the patch.
You are correct that, if gcc had variables of type "char * const" (or
"const char * const") which need to be visible from other files,
EXPORTED_CONST would not work for those variables. However, this is a
very unlikely scenario, as such variables would normally actually have
type "const char".