changeset 32:ed6ae3b865c9

Use __attribute__ ((noreturn)) on err(x) functions
author David Demelier <markand@malikania.fr>
date Sun, 25 Sep 2011 19:15:55 +0200
parents e532a973f43d
children 23a3ebcbf08e
files err.h
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/err.h	Fri Sep 23 08:58:23 2011 +0200
+++ b/err.h	Sun Sep 25 19:15:55 2011 +0200
@@ -22,21 +22,37 @@
 #include <stdarg.h>
 
 /*
+ * Attribute noreturn may helps. This may produce a warning with GCC 4.5:
+ *
+ * int a;
+ *
+ * if ((a = getstate() < 0)
+ *	errx(1, "State failed");
+ *
+ * Because compilator does not know that errx will call exit may produce
+ * a warning like `a may be used uninitialized'.
+ */
+
+#ifdef __GNUC__
+#define _NORETURN_	__attribute__ ((noreturn))
+#endif
+
+/*
  * err() functions append the format message to the stderr FILE pointer. They
  * also append the system error using strerror(errno). Then the functions exit
  * with the error code given as first argument.
  */
 
-void	err(int, const char *, ...);
-void	verr(int, const char *, va_list);
+void	err(int, const char *, ...) _NORETURN_;
+void	verr(int, const char *, va_list) _NORETURN_;
 
 /*
  * errx() functions are similar to err() except that they do not append the
  * system error message.
  */
 
-void	errx(int, const char *, ...);
-void	verrx(int, const char *, va_list);
+void	errx(int, const char *, ...) _NORETURN_;
+void	verrx(int, const char *, va_list) _NORETURN_;
 
 /*
  * warn() functions are similar to err() but they do not call exit().