This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
inline functions not getting internal linkage in x86 without optimization
- To: egcs-bugs at cygnus dot com
- Subject: inline functions not getting internal linkage in x86 without optimization
- From: marc_auslander at us dot ibm dot com
- Date: Thu, 25 Jun 1998 16:02:01 -0400
Consider the following two files:
foo.c
int x;
void foo();
inline void bar() { x=1; };
main()
{
foo();
bar();
}
bar.c
void bar();
extern int x;
void foo()
{
x=2;
bar();
}
void bar()
{
x=1;
}
Makefile:
foo: foo.o bar.o Makefile
g++ $(CFLAGS) -Wall foo.o bar.o -o foo
foo.o: foo.c Makefile
g++ -x c++ $(CFLAGS) -Wall -c foo.c -o foo.o
bar.o: bar.c Makefile
g++ -x c++ $(CFLAGS) -Wall -c bar.c -o bar.o
When compiled without optimization, I get:
make
g++ -x c++ -Wall -c foo.c -o foo.o
g++ -x c++ -Wall -c bar.c -o bar.o
g++ -Wall foo.o bar.o -o foo
bar.o(.text+0x18):bar.cc: multiple definition of `bar(void)'
foo.o(.text$bar__Fv+0x0):foo.cc: first defined here
make: *** [foo] Error 1
when compiled with optimization, this error does not happen.
My interpretation is that, without optimization, the compiler is emitting
the code for the inline'd bar in compiling foo, and giving it external
linkage. C++ specifies that inline implies internal linkage.
The same experiment on PwrPC/AIX does NOT fail in this way. Without
optimization, the code for bar is generated inside foo.o with internal
linkage.
(~/tmp) g++ --version
egcs-2.90.27 980315 (egcs-1.0.2 release)
(~/tmp)
Marc Auslander <Marc_Auslander@us.ibm.com> 914 945-4346 (Tieline 862
Fax x4425)