This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

error.h redefining __attribute__() when __STRICT_ANSI__ is defined (std=c99)


we hit a neat little error with some code when including error.h and 
using -std=c99 ... the question is whether this is a feature :)

take for example the attached code ... when built with -std=c99, 
__STRICT_ANSI__ is defined by gcc which causes error.h to macro away the gcc  
__attribute__ extension since gcc doesnt consider __attribute__ to ever be 
defined

perhaps a better idea would be to use __error_attribute__ inside of the header 
so that it doesnt pollute the namespace of the code that includes it ... 
patch attached
-mike
#include <error.h>

# define strong_alias(name, aliasname) \
	extern __typeof (name) aliasname __attribute__ ((alias (#name)));

int main() { return 0; }

strong_alias(main, main_foo)
2006-04-07  Mike Frysinger  <vapier@gentoo.org>

	* misc/error.h (__attribute__): Rename to __error_attribute__.
	(__format__): Rename to __error_format__.
	(__printf__): Rename to __error_printf__.
	(error): Update prototype to use new names.
	(error_at_line): Likewise.

--- misc/error.h
+++ misc/error.h
@@ -1,5 +1,5 @@
 /* Declaration for error-reporting function
-   Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -20,16 +20,21 @@
 #ifndef _ERROR_H
 #define _ERROR_H 1
 
-#ifndef __attribute__
+#ifndef __error_attribute__
 /* This feature is available in gcc versions 2.5 and later.  */
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(Spec) /* empty */
+#  define __error_attribute__(Spec) /* empty */
+# else
+#  define __error_attribute__(Spec) __attribute__(Spec)
 # endif
 /* The __-protected variants of `format' and `printf' attributes
    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-#  define __format__ format
-#  define __printf__ printf
+#  define __error_format__ format
+#  define __error_printf__ printf
+# else
+#  define __error_format__ __format__
+#  define __error_printf__ __printf__
 # endif
 #endif
 
@@ -44,11 +49,11 @@ extern "C" {
    If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
 
 extern void error (int __status, int __errnum, const char *__format, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
+     __error_attribute__ ((__error_format__ (__error_printf__, 3, 4)));
 
 extern void error_at_line (int __status, int __errnum, const char *__fname,
 			   unsigned int __lineno, const char *__format, ...)
-     __attribute__ ((__format__ (__printf__, 5, 6)));
+     __error_attribute__ ((__error_format__ (__error_printf__, 5, 6)));
 
 /* If NULL, error will flush stdout, then print on stderr the program
    name, a colon and a space.  Otherwise, error will call this

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