> Does exist a way to let the preprocessor know which is the current > compiler version? > Any suggestion would be greatly appreciated... cat > 11 <<EOF # if ( __GNUC__ == 3 ) gcc = 3.x.x. #else gcc != 3.x.x. #endif EOF [shitov@borlin58 NTest]$ gcc --version gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5) Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [shitov@borlin58 NTest]$ cpp -gcc 11 # 1 "11" # 1 "<built-in>" # 1 "<command line>" # 1 "11" gcc = 3.x.x. [shitov@borlin34 NTest]$ gcc --version 2.96 [shitov@borlin34 NTest]$ cpp -gcc 11 # 4 "11" gcc != 3.x.x. For extended check you can use other variables as it is described in cpp doc: -- from cpp 3.2.2 info: ---------> `__GNUC__' `__GNUC_MINOR__' `__GNUC_PATCHLEVEL__' These macros are defined by all GNU compilers that use the C preprocessor: C, C++, and Objective-C. Their values are the major version, minor version, and patch level of the compiler, as integer constants. For example, GCC 3.2.1 will define `__GNUC__' to 3, `__GNUC_MINOR__' to 2, and `__GNUC_PATCHLEVEL__' to 1. They are defined only when the entire compiler is in use; if you invoke the preprocessor directly, they are not defined. `__GNUC_PATCHLEVEL__' is new to GCC 3.0; it is also present in the widely-used development snapshots leading up to 3.0 (which identify themselves as GCC 2.96 or 2.97, depending on which snapshot you have). If all you need to know is whether or not your program is being compiled by GCC, you can simply test `__GNUC__'. If you need to write code which depends on a specific version, you must be more careful. Each time the minor version is increased, the patch level is reset to zero; each time the major version is increased (which happens rarely), the minor version and patch level are reset. If you wish to use the predefined macros directly in the conditional, you will need to write it like this: /* Test for GCC > 3.2.0 */ #if __GNUC__ > 3 || \ (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && \ __GNUC_PATCHLEVEL__ > 0)) Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold: #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) ... /* Test for GCC > 3.2.0 */ #if GCC_VERSION > 30200 Many people find this form easier to understand. -- from cpp 3.2.2 info: ---------> Best, Yuri
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET