Multiple errors from C assert macro -


i have assert macro that's defined as:

#define likely(cond) (__builtin_expect((cond), 1)) #define unlikely(cond) (__builtin_expect(!!(cond), 0))  static void assert_fail(const char *__assertion, const char *__file,                            unsigned int __line, const char *__function) {     fprintf(stderr, "\nassert failed %s:%d %s()\n%s\n", __file, __line, __function, __assertion);      void *array[50];     size_t size = backtrace(array, 50);     // fill out array of pointers stack entries     backtrace_symbols_fd(&array[1], size, stderr_fileno);     exit(1); }  #define assert(expr) ( likely(expr) ? (void) (0) : \                        assert_fail(#expr, __file__, __line__, __func__ )) 

which works fine, except when make simple error inside assert condition, eg wrong variable name:

assert(size > 0); 

it prints sensible error, 5 notes (including repeats) makes harder read. there sane way address make easier read? core issue seems use of macros, can't see how avoid here, given use of __file__, __line__, etc.

disabling "note: each undeclared identifier reported once each function" cut in half if possible (though cannot find way that)

abc.c: in function 'init': abc.c:53:12: error: 'size' undeclared (first use in function)      assert(size > 0);             ^ include/assert.h:21:41: note: in definition of macro 'likely'  #define likely(cond) (__builtin_expect((cond), 1))                                          ^ abc.c:53:5: note: in expansion of macro 'assert'      assert(size > 0);      ^ abc.c:53:12: note: each undeclared identifier reported once each function appears in      assert(size > 0);             ^ include/assert.h:21:41: note: in definition of macro 'likely'  #define likely(cond) (__builtin_expect((cond), 1))                                          ^ abc.c:53:5: note: in expansion of macro 'assert'      assert(size > 0);      ^ 

as general rule, when dealing compiler errors, address first error find recompile. way don't waste time chasing down cascading errors.

in particular case, you'll notice have "error" line followed several "note" lines. whenever see "note" message, it's giving additional information on recent "error" or "warning message". shouldn't suppress messages these (and don't believe can), can give valuable information on true source of error.

here's example of these "note" messages useful:

#include <stdio.h>  void f1(double x);  int main() {     f1(3);     return 0; }   void f1(int x) {     printf("x=%d\n", x); } 

in code declaration of f1 doesn't match definition. compiler generate following message:

x1.c:12:6: error: conflicting types ‘f1’  void f1(int x)       ^ x1.c:3:6: note: previous declaration of ‘f1’ here  void f1(double x); 

the "error" message tells definition @ line 12 doesn't match declaration, doesn't declaration conflicts with. appears in "note" message follows. in large project, might have trouble finding conflict without "note" message.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -