tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
GNU inline functions
Hi,
gcc has some non standard interpretations of inline function declarations,
there is a fairly good summary of the problems at
http://www.greenend.org.uk/rjk/2003/03/inline.html
but basically, the C99 standard
http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
says that declaring an "extern" inline function causes an externally
callable symbol to be defined, whereas traditional gcc (prior to 4.3 or
using the std=gnu99) does not, as per the following
% cat i.c
inline void foo (void)
{
}
extern inline void bar (void)
{
}
static inline void baz (void)
{
}
int
main(int ac, char *av[])
{
foo();
bar();
baz();
return 0;
}
% pcc -c i.c && nm i.o
00000000 T bar
0000002c t baz
U foo
00000008 T main
% gcc -c i.c && nm i.o
U bar
00000033 t baz
00000000 T foo
00000005 T main
This affects pcc which now has some gcc compatibility built in but follows
the C99 standard wrt inline functions, causing programs using sigsetops(3)
in multiple source files to fail link because of multiply defined symbols.
The patch below allows such programs (eg usr.bin/ftp) to build properly
with gcc 4.1.3 (in-tree) and pcc (-current) and should continue to work
with gcc 4.3 and beyond
any objections to committing that?
iain
Index: signal.h
===================================================================
RCS file: /cvsroot/src/include/signal.h,v
retrieving revision 1.51
diff -u -r1.51 signal.h
--- signal.h 11 Jan 2009 03:04:12 -0000 1.51
+++ signal.h 27 Mar 2010 07:13:32 -0000
@@ -101,7 +101,11 @@
#endif
#ifndef _SIGINLINE
+#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
#define _SIGINLINE extern __inline
+#else
+#define _SIGINLINE __inline
+#endif
#endif
_SIGINLINE int
Home |
Main Index |
Thread Index |
Old Index