[gcc-in-cxx] In C++ declare const variables explicitly extern

Ian Lance Taylor iant@google.com
Sun Feb 1 06:33:00 GMT 2009


The linkage sematics of variables declared with only the const
qualifier are different in C and C++.  In C such variables have
external linkage.  In C++ they do not.  gcc naturally expects the C
behaviour.  This changes some variables in gcc to use an explicit
"extern const" declaration where necessary.  Most of the cases are in
the generator programs, when writing out const arrays.  This should
perhaps be done using a macro, but I just use #ifdef __cplusplus.

This patch also removes the inline qualifier from a function in
gimple.c, for a similar reason.  An inline function in C++ has
internal linkage, but gcc expects this function to have external
linkage.

Committed to gcc-in-cxx branch.

Ian


2009-01-31  Ian Lance Taylor  <iant@google.com>

	* genattrtab.c (write_length_unit_log): If C++, declare const to
	be extern.
	* genchecksum.c (dosum): Likewise.
	* gengtype.c (write_rtx_next, finish_root_table): Likewise.
	(write_roots): Likewise.
	* dummy-checksum.c (executable_checksum): Likewise.
	* gimple.c (gimple_ops_offset_): Likewise.
	(gimplify_assign): Do not declare as inline.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 4517 bytes
Desc: Declare const variables explicitly extern
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090201/165fbe53/attachment.bin>


More information about the Gcc-patches mailing list