This is the mail archive of the gcc-patches@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: PATCH COMMITTED: EXPORTED_CONST


Jay Foad <jay.foad@gmail.com> 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[]".

Ian


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