Closed tkralphs closed 3 years ago
As far as I understand this part in configure, it tries to figure out what compiler flags to add to get C11 and C++11, resp, or higher. The "none needed" means that the C (C++) compiler by default supports C11 (C++11).
To check in C code whether you have C11 or higher, doing a
#if defined(_MSC_VER) || __STDC_VERSION__ >= 201112L
should work (MS doesn't support full C11, but maybe the part you are interested in (?), if you meant C).
To check in C++ code whether you have C++11 or higher, doing a
#if __cplusplus >= 201103L
should be sufficient. (I recently added some flags to enable a bugfix that makes this work with the MS/Intel builds on Windows, too: 6ef7a97).
For CoinUtils, we also have a COINUTILS_CPLUSPLUS11
that is defined if C++11 is/was available when compiling CoinUtils.
Yeah, I knew how to detect C11 manually, but I'm asking if it makes sense to just have some standard symbol automatically defined across all projects that use the build tools without having to do anything. Having this work like other autoheader HAVE_*
seems to just make everything easier and more standardized. It looks as though the autotools have established HAVE_CXXYY
as the "standard" symbol for this. Putting one or more call to AX_CXX_COMPILE_STDCXX
into coin.m4
will mean I don't have to think about this and we don't have a mix of different symbols being used. Of course, it is possible that the detection is not what you would want (it may say Visual Studio doesn't have C11 support, for example, when it mostly does).
As a secondary question, I understand from the output that configure
is checking to see what flags need to be used to get CXXYY support, but I was also asking how I find out what those flags are? Looking directly into the configure
script, I guess that there are some variables set that can be extracted from config.status
(e.g., ac_cv_prog_cc_c11
, but it doesn't look like the whole thing is set up so that one is meant to be able to easily extract this information. I'm just not sure what the point of that check is then. Is there a way you can then automatically add the right flags?
Regarding the second question, my impression is that the flag gets added automatically to CC
/CXX
:
https://github.com/coin-or/CoinUtils/blob/54f3d8cccd5fc7931e3b635ff7b1c2ab1d57b461/configure#L4993-L5006
I'll leave the first question open for now.
__STDC_VERSION__
into various HAVE_CYY
defines.compile
script, if that isn't there already.__cplusplus
into various HAVE_CXXYY
defines is so helpful. Nothing prevents authors to keep checking __cplusplus
instead of the new HAVE_CXXYY
, so adding another symbol doesn't really prevent a "mix of different symbols".
The COINUTILS_CPLUSPLUS11
exists because we want to have a COINUTILS_...
symbol that we can export in CoinUtilsConfig.h
, so code that compiles against CoinUtils knows whether CoinUtils was compiled in "C++11-mode". But HAVE_CXXYY
defines would only be used internally.I'm still confused whether you want to check the version of C, C++, or both. You write C11, but then suggest to use macro AX_CXX_COMPILE_STDCXX
and define HAVE_CXXYY
.
Sorry, for the purposes of this issues, I only care about C++, not C. Everywhere I wrote anything about C11, I meant C++11.
It's odd to me that configure automatically adds the flags to get C++11 support by default. What if I want to build without C++11 support? If the philosophy is that I should want it whenever I can have it, then why don't compilers just provide it by default?
I haven't checked whether there is a way to disable the feature that configure tries to enable C++11. I could dig into it, if the "What if" is not only theoretical.
As far as I know, current compilers provide C++11 by default. At least, current GCC's default is at -std=gnu++17
, my clang says gnu++14
, and not-too-old MS compilers also do C++11 or something higher by default. Enabling C++11 with an extra switch could have been necessary when using old compilers (late 200x, early 201x) that support C++11 already, but don't have it enabled at default.
I thought about adding additional flags to AC_COIN_PROG_CXX
to specify what version of C++ is desired or required, but that didn't seem to be much better than just putting an appropriate AX_CXX_COMPILE_STDCXX
into configure.ac
. I added a mention of AX_CXX_COMPILE_STDCXX
to the docu, for what it's worth.
Since configure already tries to ensure C++11, this should also work with MSVS, and success of this is easy to check (__cplusplus >= 201103L
), I don't think I'll add uses of AX_CXX_COMPILE_STDCXX
by default.
I noticed that with the standard build tools setup, there seems to be some kind of automatic check for C11 support, e.g., I see output like
here. But I don't really see where this is triggered or how exactly to use the result. What I would like is to have the symbol
HAVE_CXX11
defined when C11 support is present, which I can get if I addto
configure.ac
. What do you think about just making this standard across all projects by adding it to e.g., AC_COIN_PROG_CXX?