SEC15_GNUC.hss 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. [Main]
  2. Title=__GNUC__
  3. See Also=SEC15_GNUC_MINOR: __GNUC_MINOR__, SEC15_GNUC_PATCHLEVEL: __GNUC_PATCHLEVEL__
  4. [Top]
  5. This macro is always defined in GCC. The value identifies the GCC major
  6. version number (currently '3').
  7. <BR><BR>
  8. If all you need to know is whether or not your program is being compiled
  9. by GCC, you can simply test <CODE>__GNUC__</CODE>. If you need to write code
  10. which depends on a specific version, you must be more careful. Each
  11. time the minor version is increased, the patch level is reset to zero;
  12. each time the major version is increased (which happens rarely), the
  13. minor version and patch level are reset. If you wish to use the
  14. predefined macros directly in the conditional, you will need to write it
  15. like this:
  16. <PRE>/* Test for GCC &gt; 3.2.0 */
  17. #if __GNUC__ &gt; 3 || \
  18. (__GNUC__ == 3 &amp;&amp; (__GNUC_MINOR__ &gt; 2 || \
  19. (__GNUC_MINOR__ == 2 &amp;&amp; \
  20. __GNUC_PATCHLEVEL__ &gt; 0))
  21. </PRE>
  22. Another approach is to use the predefined macros to
  23. calculate a single number, then compare that against a threshold:
  24. <PRE>#define GCC_VERSION (__GNUC__ * 10000 \
  25. + __GNUC_MINOR__ * 100 \
  26. + __GNUC_PATCHLEVEL__)
  27. ...
  28. /* Test for GCC &gt; 3.2.0 */
  29. #if GCC_VERSION &gt; 30200
  30. </PRE>
  31. Many people find this form easier to understand.