H
Henry Townsend
Consider the little program below. It simply attempts to determine what
version of what compiler it was built with via documented preprocessor
macros and print out the result. When the compiler is gcc it works fine,
because __VERSION__ is supplied as a string. But identifying the Sun
compiler is harder because it provides __SUNPRO_C as a numerical value
(equal in my case to 0x580). My attempt to stringify it produces an error:
% cc -g -o foo foo.c
"foo.c", line 13: invalid source character: '#'
"foo.c", line 13: syntax error before or at: 0x580
cc: acomp failed for foo.c
Is there a way to do this?
Thanks,
HT
--------------------------------------------------------------
#include <stdio.h>
#if defined(__GNUC__)
#define COMPILER_STRING "gcc " __VERSION__
#elif defined(__SUNPRO_C)
#define COMPILER_STRING "SunStudio " #__SUNPRO_C
#else
#define COMPILER_STRING "unknown compiler/version"
#endif
int main(void)
{
printf("Compiled with %s\n", COMPILER_STRING);
return 0;
}
version of what compiler it was built with via documented preprocessor
macros and print out the result. When the compiler is gcc it works fine,
because __VERSION__ is supplied as a string. But identifying the Sun
compiler is harder because it provides __SUNPRO_C as a numerical value
(equal in my case to 0x580). My attempt to stringify it produces an error:
% cc -g -o foo foo.c
"foo.c", line 13: invalid source character: '#'
"foo.c", line 13: syntax error before or at: 0x580
cc: acomp failed for foo.c
Is there a way to do this?
Thanks,
HT
--------------------------------------------------------------
#include <stdio.h>
#if defined(__GNUC__)
#define COMPILER_STRING "gcc " __VERSION__
#elif defined(__SUNPRO_C)
#define COMPILER_STRING "SunStudio " #__SUNPRO_C
#else
#define COMPILER_STRING "unknown compiler/version"
#endif
int main(void)
{
printf("Compiled with %s\n", COMPILER_STRING);
return 0;
}