S
sathya_me
friends,
Please go through the following code which I have downloaded from Bob
Stout (Snippets):
#include <stdio.h>
void main(void) /* Actually, void main() is non-ANSI/ISO */
{
int version;
#if defined(__ZTC__)
#ifdef __SC__
printf("Symantec C++ ver. %x.%x\n", __SC__ >> 8, __SC__ & 0xff);
#else
printf("Zortech C++ ver. %x.%xr%x\n",
__ZTC__ >> 8, (__ZTC__ >> 4) & 0xf, __ZTC__ & 0xf);
#endif
#elif defined(__WATCOMC__)
printf("Watcom C/C++ ver. %d.%d\n",
__WATCOMC__ / 100, __WATCOMC__ % 100);
#elif defined(__TURBOC__)
version = __TURBOC__;
if (0x295 > version)
{
printf("Borland Turbo C ver. %x.%02x\n",
version >> 8, version & 0xff);
}
else if (0x400 <= version)
{
printf("Borland C++ ver. %x.%x\n",
(version >> 8) - 1, (version & 0xff) >> 4);
}
else if (0x297 > version)
printf("Borland Turbo C++ ver. 1.%02x\n", version - 0x295);
else printf("Borland C++ ver. 2.%02x\n", version - 0x297);
#elif defined(_QC)
printf("Microsoft Quick C ver. %d.%d\n", _QC / 100, _QC % 100);
#elif defined(_MSC_VER)
printf("Microsoft C(/C++) ver. %d.%d\n",
_MSC_VER / 100, _MSC_VER % 100);
#elif defined(__POWERC)
printf ("MIX Power C ver. %d\n", __POWERC);
#else
puts("Unknown compiler!");
#endif
}
I have downloaded the above program which prints the specified compiler
by which the code is been compiled. I have tested with MSVC and TC++, GCC.
The out-put was exactly same as excepted. It throws "Unknown compiler!"
for GCC. Even though the following code did use some of the non- ANSI
standard
specific can anybody explain the following:
1)__ZTC__ , __SC__ etc. are predefined macros (correct me if I am
wrong).
Can any body explain how this work during the compile / run time?
(I am
not sure weather this evaluated during the compile or run time)
2) Why there are some of the operators are used in the printf. Can
any body
explain why?
3) Is this the way the C code becomes portable. If yes then is it
possible
to make a C code portable with different OS, processors.
4)I want to know more about the above. Any link on the web
If the above is discussed in FAQ or it is a OT please guide me to the
correct
NG.
Thanks
--
"Combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan25 AT yahoo DOT com
(remove the AT and DOT)
Please go through the following code which I have downloaded from Bob
Stout (Snippets):
#include <stdio.h>
void main(void) /* Actually, void main() is non-ANSI/ISO */
{
int version;
#if defined(__ZTC__)
#ifdef __SC__
printf("Symantec C++ ver. %x.%x\n", __SC__ >> 8, __SC__ & 0xff);
#else
printf("Zortech C++ ver. %x.%xr%x\n",
__ZTC__ >> 8, (__ZTC__ >> 4) & 0xf, __ZTC__ & 0xf);
#endif
#elif defined(__WATCOMC__)
printf("Watcom C/C++ ver. %d.%d\n",
__WATCOMC__ / 100, __WATCOMC__ % 100);
#elif defined(__TURBOC__)
version = __TURBOC__;
if (0x295 > version)
{
printf("Borland Turbo C ver. %x.%02x\n",
version >> 8, version & 0xff);
}
else if (0x400 <= version)
{
printf("Borland C++ ver. %x.%x\n",
(version >> 8) - 1, (version & 0xff) >> 4);
}
else if (0x297 > version)
printf("Borland Turbo C++ ver. 1.%02x\n", version - 0x295);
else printf("Borland C++ ver. 2.%02x\n", version - 0x297);
#elif defined(_QC)
printf("Microsoft Quick C ver. %d.%d\n", _QC / 100, _QC % 100);
#elif defined(_MSC_VER)
printf("Microsoft C(/C++) ver. %d.%d\n",
_MSC_VER / 100, _MSC_VER % 100);
#elif defined(__POWERC)
printf ("MIX Power C ver. %d\n", __POWERC);
#else
puts("Unknown compiler!");
#endif
}
I have downloaded the above program which prints the specified compiler
by which the code is been compiled. I have tested with MSVC and TC++, GCC.
The out-put was exactly same as excepted. It throws "Unknown compiler!"
for GCC. Even though the following code did use some of the non- ANSI
standard
specific can anybody explain the following:
1)__ZTC__ , __SC__ etc. are predefined macros (correct me if I am
wrong).
Can any body explain how this work during the compile / run time?
(I am
not sure weather this evaluated during the compile or run time)
2) Why there are some of the operators are used in the printf. Can
any body
explain why?
3) Is this the way the C code becomes portable. If yes then is it
possible
to make a C code portable with different OS, processors.
4)I want to know more about the above. Any link on the web
If the above is discussed in FAQ or it is a OT please guide me to the
correct
NG.
Thanks
--
"Combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan25 AT yahoo DOT com
(remove the AT and DOT)