This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: A macro to test for gcc's version number


	We do this often enough that it should be a macro in ansidecl.h:

 > #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))

becomes:

 > #if HAVE_GCC_VERSION(2,7)

I'm not 100% happy with the name I chose, its kind of wordy.  Anyone
like one of these or can suggest something better?

IS_GCC(2,7)
MIN_GCC_VERS(2,7)
HAVE_GCC(2,7)

	Anyway, okay to install?

		Thanks,
		--Kaveh




1999-10-08  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

include:
	* ansidecl.h (HAVE_GCC_VERSION): New macro.  Use it.
	
gcc:
	* cppinit.c: Use HAVE_GCC_VERSION instead of explicitly testing macros.

	* gansidecl.h: Likewise.

	* rtl.c: Likewise.
	
	* rtl.h: Likewise.

	* toplev.h: Likewise.

	* tree.c: Likewise.

	* tree.h: Likewise.

	* varray.c: Likewise.

	* varray.h: Likewise.

cp:
	* cp-tree.h: Use HAVE_GCC_VERSION instead of explicitly testing macros.

f:
	* proj.h: Use HAVE_GCC_VERSION instead of explicitly testing macros.
	Don't define BUILT_WITH_270.  Define macro UNUSED in terms of
	ATTRIBUTE_UNUSED.

diff -rup orig/egcs-CVS19991008/include/ansidecl.h egcs-CVS19991008/include/ansidecl.h
--- orig/egcs-CVS19991008/include/ansidecl.h	Mon Jul 26 15:41:34 1999
+++ egcs-CVS19991008/include/ansidecl.h	Fri Oct  8 13:54:33 1999
@@ -160,16 +160,23 @@ Foundation, Inc., 59 Temple Place - Suit
 
 #endif	/* ANSI C.  */
 
+/* This macro will return true if we are using gcc, and it is of a
+   particular minimum version (both major & minor numbers are checked.)  */
+#ifndef HAVE_GCC_VERSION
+#define HAVE_GCC_VERSION(MAJOR, MINOR) \
+  (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
+#endif /* ! HAVE_GCC_VERSION */
+
 /* Define macros for some gcc attributes.  This permits us to use the
    macros freely, and know that they will come into play for the
    version of gcc in which they are supported.  */
 
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#if ! HAVE_GCC_VERSION(2,7)
 # define __attribute__(x)
 #endif
 
 #ifndef ATTRIBUTE_UNUSED_LABEL
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 93)
+# if ! HAVE_GCC_VERSION(2,93)
 #  define ATTRIBUTE_UNUSED_LABEL
 # else
 #  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
diff -rup orig/egcs-CVS19991008/gcc/cppinit.c egcs-CVS19991008/gcc/cppinit.c
--- orig/egcs-CVS19991008/gcc/cppinit.c	Mon Oct  4 07:42:21 1999
+++ egcs-CVS19991008/gcc/cppinit.c	Fri Oct  8 14:08:51 1999
@@ -212,8 +212,7 @@ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER
 
 /* If gcc is in use (stage2/stage3) we can make these tables initialized
    data. */
-#if defined __GNUC__ && (__GNUC__ > 2 \
-			 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6))
+#if HAVE_GCC_VERSION(2,7)
 /* Table to tell if a character is legal as the second or later character
    of a C identifier. */
 U_CHAR is_idchar[256] =
diff -rup orig/egcs-CVS19991008/gcc/gansidecl.h egcs-CVS19991008/gcc/gansidecl.h
--- orig/egcs-CVS19991008/gcc/gansidecl.h	Wed Sep 22 10:14:11 1999
+++ egcs-CVS19991008/gcc/gansidecl.h	Fri Oct  8 14:05:16 1999
@@ -41,7 +41,7 @@ Boston, MA 02111-1307, USA.  */
    need to do this very early; i.e. before any systems header files or
    gcc header files in case they use these keywords.  Otherwise
    conflicts might occur. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+#if HAVE_GCC_VERSION(2,7)
 # undef const
 # undef inline
 # define inline __inline__  /* Modern gcc can use `__inline__' freely. */
diff -rup orig/egcs-CVS19991008/gcc/rtl.c egcs-CVS19991008/gcc/rtl.c
--- orig/egcs-CVS19991008/gcc/rtl.c	Sun Oct  3 12:39:50 1999
+++ egcs-CVS19991008/gcc/rtl.c	Fri Oct  8 14:04:07 1999
@@ -981,7 +981,7 @@ read_rtx (infile)
   return return_rtx;
 }
 
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 void
 rtl_check_failed_bounds (r, n, file, line, func)
     rtx r;
diff -rup orig/egcs-CVS19991008/gcc/rtl.h egcs-CVS19991008/gcc/rtl.h
--- orig/egcs-CVS19991008/gcc/rtl.h	Tue Sep 28 15:41:59 1999
+++ egcs-CVS19991008/gcc/rtl.h	Fri Oct  8 14:04:47 1999
@@ -230,7 +230,7 @@ typedef struct rtvec_def{
 
 /* General accessor macros for accessing the fields of an rtx.  */
 
-#if defined ENABLE_CHECKING  && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING  && HAVE_GCC_VERSION(2,7)
 /* The bit with a star outside the statement expr and an & inside is
    so that N can be evaluated only once.  */
 #define RTL_CHECK1(RTX, N, C1)						\
@@ -1673,7 +1673,7 @@ extern void rtx_free			PROTO ((rtx));
 
 extern void fancy_abort PROTO((const char *, int, const char *))
     ATTRIBUTE_NORETURN;
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#if ! HAVE_GCC_VERSION(2,7)
 #define abort() fancy_abort (__FILE__, __LINE__, 0)
 #else
 #define abort() fancy_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
diff -rup orig/egcs-CVS19991008/gcc/toplev.h egcs-CVS19991008/gcc/toplev.h
--- orig/egcs-CVS19991008/gcc/toplev.h	Wed Sep 15 09:55:00 1999
+++ egcs-CVS19991008/gcc/toplev.h	Fri Oct  8 14:05:42 1999
@@ -51,7 +51,7 @@ extern void _fatal_insn			PROTO ((const 
 						const char *))
   ATTRIBUTE_NORETURN;
 
-#if defined __GNUC__ && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if HAVE_GCC_VERSION(2,7)
 #define fatal_insn(msgid, insn) \
 	_fatal_insn (msgid, insn, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define fatal_insn_not_found(insn) \
diff -rup orig/egcs-CVS19991008/gcc/tree.c egcs-CVS19991008/gcc/tree.c
--- orig/egcs-CVS19991008/gcc/tree.c	Fri Oct  8 07:42:44 1999
+++ egcs-CVS19991008/gcc/tree.c	Fri Oct  8 14:01:38 1999
@@ -5140,7 +5140,7 @@ get_set_constructor_bytes (init, buffer,
   return non_const_bits;
 }
 
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 /* Complain that the tree code of NODE does not match the expected CODE.
    FILE, LINE, and FUNCTION are of the caller.  */
 void
diff -rup orig/egcs-CVS19991008/gcc/tree.h egcs-CVS19991008/gcc/tree.h
--- orig/egcs-CVS19991008/gcc/tree.h	Fri Oct  8 07:42:44 1999
+++ egcs-CVS19991008/gcc/tree.h	Fri Oct  8 14:02:45 1999
@@ -323,7 +323,7 @@ struct tree_common
 
 /* When checking is enabled, errors will be generated if a tree node
    is accessed incorrectly. The macros abort with a fatal error.  */
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 
 #define TREE_CHECK(t, code)						\
 ({  const tree __t = t;							\
@@ -2519,7 +2519,7 @@ extern void dwarf2out_end_epilogue	PROTO
 
 extern void fancy_abort PROTO((const char *, int, const char *))
     ATTRIBUTE_NORETURN;
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#if ! HAVE_GCC_VERSION(2,7)
 #define abort() fancy_abort (__FILE__, __LINE__, 0)
 #else
 #define abort() fancy_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
diff -rup orig/egcs-CVS19991008/gcc/varray.c egcs-CVS19991008/gcc/varray.c
--- orig/egcs-CVS19991008/gcc/varray.c	Thu Aug 26 07:42:10 1999
+++ egcs-CVS19991008/gcc/varray.c	Fri Oct  8 14:03:10 1999
@@ -71,7 +71,7 @@ varray_grow (va, n)
 
 /* Check the bounds of a varray access.  */
 
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 
 extern void error PVPROTO ((const char *, ...))	ATTRIBUTE_PRINTF_1;
 
diff -rup orig/egcs-CVS19991008/gcc/varray.h egcs-CVS19991008/gcc/varray.h
--- orig/egcs-CVS19991008/gcc/varray.h	Wed Oct  6 17:22:39 1999
+++ egcs-CVS19991008/gcc/varray.h	Fri Oct  8 14:03:44 1999
@@ -163,7 +163,7 @@ extern varray_type varray_grow	PROTO((va
 #define VARRAY_SIZE(VA)	((VA)->num_elements)
 
 /* Check for VARRAY_xxx macros being in bound.  */
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || (__GNUC__ == 2 &&__GNUC_MINOR__ > 6))
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 extern void varray_check_failed PROTO ((varray_type, size_t,
 					const char *, int,
 					const char *)) ATTRIBUTE_NORETURN;
diff -rup orig/egcs-CVS19991008/gcc/cp/cp-tree.h egcs-CVS19991008/gcc/cp/cp-tree.h
--- orig/egcs-CVS19991008/gcc/cp/cp-tree.h	Fri Oct  8 07:42:52 1999
+++ egcs-CVS19991008/gcc/cp/cp-tree.h	Fri Oct  8 14:01:03 1999
@@ -123,7 +123,7 @@ Boston, MA 02111-1307, USA.  */
 
 /* Language-specific tree checkers. */
 
-#if defined ENABLE_CHECKING && (__GNUC__ > 2 || __GNUC_MINOR__ > 6)
+#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
 
 #define VAR_OR_FUNCTION_DECL_CHECK(NODE)			\
 ({  const tree __t = NODE;					\
diff -rup orig/egcs-CVS19991008/gcc/f/proj.h egcs-CVS19991008/gcc/f/proj.h
--- orig/egcs-CVS19991008/gcc/f/proj.h	Tue Feb 16 10:20:27 1999
+++ egcs-CVS19991008/gcc/f/proj.h	Fri Oct  8 13:59:47 1999
@@ -31,18 +31,10 @@ the Free Software Foundation, 59 Temple 
 #endif
 #include "system.j"
 
-#if !defined (__GNUC__) || (__GNUC__ < 2)
+#if ! HAVE_GCC_VERSION(2,0)
 #error "You have to use gcc 2.x to build g77 (might be fixed in g77-0.6)."
 #endif
 
-#ifndef BUILT_WITH_270
-#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-#define BUILT_WITH_270 1
-#else
-#define BUILT_WITH_270 0
-#endif
-#endif	/* !defined (BUILT_WITH_270) */
-
 /* Include files everyone gets.  <assert.h> is needed for assert().
    <stddef.h> is needed for offsetof, but technically also NULL,
    size_t, ptrdiff_t, and so on.  */
@@ -69,11 +61,7 @@ typedef enum
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
 #ifndef UNUSED	/* Compile with -DUNUSED= if cc doesn't support this. */
-#if BUILT_WITH_270
-#define UNUSED __attribute__ ((unused))
-#else	/* !BUILT_WITH_270 */
-#define UNUSED
-#endif	/* !BUILT_WITH_270 */
+#define UNUSED ATTRIBUTE_UNUSED
 #endif  /* !defined (UNUSED) */
 
 #ifndef dmpout


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]