[CoinUtils-tickets] [COIN-OR Common Utilities] #6: Sun CC compiler
generates warnings about linkage
COIN-OR Common Utilities
coin-trac at coin-or.org
Wed Oct 4 11:58:18 EDT 2006
#6: Sun CC compiler generates warnings about linkage
------------------------+---------------------------------------------------
Reporter: mjs | Owner: somebody
Type: defect | Status: new
Priority: minor | Milestone:
Component: component1 | Version:
Keywords: |
------------------------+---------------------------------------------------
During a make of CLP using the Solaris CC compiler (CC: Sun C++ 5.7
2005/01/07), the following warnings are generated:
{{{
/bin/bash ../libtool --tag=CXX --mode=compile CC -DHAVE_CONFIG_H -I.
-I`echo .` -I../inc -O4 -DNDEBUG -c -o CoinModelUseful2.lo
CoinModelUseful2.cpp
CC -DHAVE_CONFIG_H -I. -I. -I../inc -O4 -DNDEBUG -c CoinModelUseful2.cpp
-KPIC -DPIC -o .libs/CoinModelUseful2.o
"CoinModelUseful2.cpp", line 764: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 765: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 766: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 767: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 768: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 769: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 770: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
"CoinModelUseful2.cpp", line 771: Warning (Anachronism): Using extern "C"
double(*)(double) to initialize double(*const)(double).
8 Warning(s) detected.
}}}
The offending lines in CoinModelUseful2.cpp are:
{{{
struct init
{
char const *fname;
double (*fnct) (double);
};
struct init const arith_fncts[] =
{
{"sin", sin},
{"cos", cos},
{"atan", atan},
{"ln", log},
{"exp", exp},
{"sqrt", sqrt},
{"fabs", fabs},
{"abs", fabs},
{NULL, 0}
};
}}}
See the discussion here: http://docs.sun.com/source/819-3689/Ch3.Std.html,
Section 3.11.
The problem is that the standard C library functions are declared with "C"
linkage in the Sun libraries. The "anachronism" and the fact that they
are warnings stem from the fact that "C" and "C++" linkage are binary-
compatible in the Sun libs, but (a) they need not be (in which case,
things are likely to break), and (b) the C++ standard permits standard C
lib functions to have either "C" or "C++" linkage.
The warning can be eliminated in this case by enclosing the declaration of
struct init in
extern "C" {...} (and similarly enclosing the declaration of struct symrec
in !CoinModelUseful.hpp), but for systems where the standard C functions
have C++ linkage, that won't work. I can't think of a completely portable
way to handle this other than to define in !BuildTools a preprocessor
symbol such as STD_C_FUNCTION_LINKAGE, which is defined to be C or C++
depending on the compiler and define the structs inside extern
"STD_C_FUNCTION_LINKAGE" {...}. Even that's not quite ideal, as the
structs could then only be used to hold pointers to standard C functions.
--
Ticket URL: <https://projects.coin-or.org/CoinUtils/ticket/6>
COIN-OR Common Utilities <http://example.com/>
My example project
More information about the CoinUtils-tickets
mailing list