[BUG] inline macro define in glib.h breaks C++ compilation on Digital Unix V4.0D
- From: wtc netscape com (Wan-Teh Chang)
- To: gtk-list redhat com
- CC: akkana netscape com
- Subject: [BUG] inline macro define in glib.h breaks C++ compilation on Digital Unix V4.0D
- Date: Fri, 11 Dec 1998 23:05:53 -0800
Package: glib-1.1.5
OS revision: Digital Unix V4.0D
Compilers: native compilers cc and cxx
Description:
The configure script of glib detects whether the C compiler
supports 'inline', '__inline', and '__inline__', and defines the
macros G_HAVE_INLINE, G_HAVE___INLINE, and
G_HAVE___INLINE__ in glibconfig.h accordingly.
Digital Unix's native C compiler cc only supports '__inline'.
So G_HAVE___INLINE is defined in glibconfig.h.
This enables the following macro definition in glib.h:
#define inline __inline
But Digital Unix's native C++ compiler cxx does not
understand '__inline'. So if a C++ file includes glib.h
and uses the 'inline' keyword, it won't compile.
See the attached file test-case.txt for an example.
Fix:
1. Since 'inline' is a standard C++ feature, glibconfig.h
should define G_HAVE_INLINE if __cplusplus
is defined. Please see the attached patch file for
configure.in (diff.configure.in.txt).
2. Because inline functions are non-standard C language
extensions, I would suggest that glib not use inline
functions at all. Use macros instead. Writing only in
standard C makes the code more portable.
Wan-Teh Chang
wtc@netscape.com
*** configure.in.orig Sat Nov 14 12:54:01 1998
--- configure.in Fri Dec 11 22:25:25 1998
***************
*** 613,619 ****
--- 613,623 ----
$glib_vacopy
+ #ifdef __cplusplus
+ #define G_HAVE_INLINE 1
+ #else
$glib_inline
+ #endif /* __cplusplus */
#define G_BYTE_ORDER $g_byte_order
outfile_EOF
trex0:/u/wtc 75% cat bar.cpp
inline int foo(int i) {return i;}
int main()
{
int j;
j = foo(3);
return 0;
}
trex0:/u/wtc 76% cxx bar.cpp
trex0:/u/wtc 77% cat foo.cpp
#include <glib.h>
inline int foo(int i) {return i;}
int main()
{
int j;
j = foo(3);
return 0;
}
trex0:/u/wtc 78% cxx -I/usr/users/wtc/include -I/usr/users/wtc/lib/glib/include
foo.cpp
cxx: Warning: /usr/users/wtc/include/glib.h, line 1297: omission of explicit
type is nonstandard ("int" assumed)
static inline void
-------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1297: expected a ";"
static inline void
--------------^
cxx: Warning: /usr/users/wtc/include/glib.h, line 1326: parsing restarts here
after previous syntax error
typedef void (*GPrintFunc) (const gchar *string);
----------------------------------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1329: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_print_handler (GPrintFunc func);
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1329: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_print_handler (GPrintFunc func);
-----------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1332: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_printerr_handler (GPrintFunc func);
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1332: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_printerr_handler (GPrintFunc func);
-----------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1339: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_message_handler (GPrintFunc func);
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1339: identifier "GPrintFunc"
is undefined
GPrintFunc g_set_message_handler (GPrintFunc func);
------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1536: expected a type
specifier
G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1536: "gint" has already been
declared in the current scope
G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
--------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1536: expected a ";"
G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1539: expected a
type specifier
G_INLINE_FUNC gint
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1539: declaration
has already been defined by variable "gint" (declared at line 1536)
G_INLINE_FUNC gint
--------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1540: expected a ";"
g_bit_nth_lsf (guint32 mask,
^
cxx: Warning: /usr/users/wtc/include/glib.h, line 1555: parsing restarts here
after previous syntax error
gint nth_bit);
-------------------------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1557: expected a
type specifier
G_INLINE_FUNC gint
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1557: declaration
has already been defined by variable "gint" (declared at line 1539)
G_INLINE_FUNC gint
--------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1558: expected a ";"
g_bit_nth_msf (guint32 mask,
^
cxx: Warning: /usr/users/wtc/include/glib.h, line 1574: parsing restarts here
after previous syntax error
G_INLINE_FUNC guint g_bit_storage (guint number);
----------------------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1576: expected a
type specifier
G_INLINE_FUNC guint
^
cxx: Error: /usr/users/wtc/include/glib.h, line 1576: "guint" has
already been declared in the current scope
G_INLINE_FUNC guint
--------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1577: expected a ";"
g_bit_storage (guint number)
^
cxx: Warning: /usr/users/wtc/include/glib.h, line 1593: parsing restarts here
after previous syntax error
GStringChunk* g_string_chunk_new (gint size);
------------------------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1604: expected a ")"
GString* g_string_sized_new (guint dfl_size);
------------------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1606: expected a type
specifier
gint free_segment);
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1610: expected a type
specifier
gint len);
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1620: expected a type
specifier
gint pos,
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1623: expected a type
specifier
gint pos,
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1626: expected a type
specifier
gint pos,
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1627: expected a type
specifier
gint len);
-----------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1649: expected a type
specifier
guint element_size);
-----------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1654: expected a type
specifier
guint len);
-----------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1657: expected a type
specifier
guint len);
-----------------------------------^
cxx: Error: /usr/users/wtc/include/glib.h, line 1659: expected a type
specifier
guint length);
-----------------------------------^
cxx: Info: Error limit reached.
cxx: Info: 30 errors detected in the compilation of "foo.cpp".
cxx: Info: Compilation terminated.
trex0:/u/wtc 79%
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]