Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sun CC compiler generates warnings about linkage #6

Closed
svigerske opened this issue Mar 2, 2019 · 4 comments
Closed

Sun CC compiler generates warnings about linkage #6

svigerske opened this issue Mar 2, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@svigerske
Copy link
Member

Issue created by migration from Trac.

Original creator: @mjsaltzman

Original creation time: 2006-10-04 15:58:18

Assignee: somebody

Version:

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.

@svigerske svigerske added bug Something isn't working minor labels Mar 2, 2019
@svigerske
Copy link
Member Author

Comment by ladanyi created at 2006-12-10 04:50:14

Will fix it later when we figure out how to do it properly. For now, let's live with the warnings...

--Laci

@svigerske
Copy link
Member Author

Comment by ladanyi created at 2006-12-10 04:50:14

Changing assignee from somebody to ladanyi.

@svigerske
Copy link
Member Author

Comment by ladanyi created at 2006-12-10 04:50:14

Changing status from new to assigned.

@svigerske
Copy link
Member Author

The offending code had been changed to

struct init {
  char const *fname;
  double (*fnct)(double);
};

inline double sin_wrapper(double x) { return sin(x); }
inline double cos_wrapper(double x) { return cos(x); }
inline double atan_wrapper(double x) { return atan(x); }
inline double log_wrapper(double x) { return log(x); }
inline double exp_wrapper(double x) { return exp(x); }
inline double sqrt_wrapper(double x) { return sqrt(x); }
inline double fabs_wrapper(double x) { return fabs(x); }
inline double floor_wrapper(double x) { return floor(x); }
inline double ceil_wrapper(double x) { return ceil(x); }

struct init const arith_fncts[] = {
  { "sin", sin_wrapper },
  { "cos", cos_wrapper },
  { "atan", atan_wrapper },
  { "ln", log_wrapper },
  { "exp", exp_wrapper },
  { "sqrt", sqrt_wrapper },
  { "fabs", fabs_wrapper },
  { "abs", fabs_wrapper },
  { "floor", floor_wrapper },
  { "ceil", ceil_wrapper },
  { NULL, 0 }
};

in f209c9b (BSP 12 years ago).

I'll assume that this fixed the issue. Please reopen if you can still reproduce with current code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant