Skip to content

The error macros are problematic #6

@richfitz

Description

@richfitz

I get a number of compiler warnings from the softfailure, hardfailure and ERROR macros (and function macros are pretty gross in general IMO).

There are a few approaches to fixing these, but all will involve some moderate refactoring of the code. You may have thoughts on how best to do this, or be looking at other bits of refactoring that would overlap.

With clang (Apple LLVM version 7.0.0 (clang-700.0.72)) and with -Wall -Wextra -pedantic -Wno-unused-parameter I see

In file included from liblsoda/src/lsoda.c:72:
liblsoda/src/lsoda_internal.h:18:106: warning: token pasting of ',' and
      __VA_ARGS__ is a GNU extension [-Wgnu-zero-variadic-macro-arguments]
  ...ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE_...
                                                      ^
liblsoda/src/lsoda.c:174:3: warning: C99 forbids conditional expressions with
      only one void side [-Wpedantic]
                ERROR("[lsoda] neq = %d is less than 1\n", ctx->neq);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
liblsoda/src/lsoda_internal.h:18:37: note: expanded from macro 'ERROR'
#define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strd...
                                    ^~~~~~~~~~~~~~~~
liblsoda/src/lsoda_internal.h:18:106: warning: token pasting of ',' and
      __VA_ARGS__ is a GNU extension [-Wgnu-zero-variadic-macro-arguments]
  ...ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE_...
                                                      ^
liblsoda/src/lsoda.c:190:5: warning: C99 forbids conditional expressions with
      only one void side [-Wpedantic]
  ...ERROR("[lsoda] rtol = %g is less than 0.\n", rtoli);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
liblsoda/src/lsoda_internal.h:18:37: note: expanded from macro 'ERROR'
#define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strd...
                                    ^~~~~~~~~~~~~~~~
liblsoda/src/lsoda_internal.h:18:106: warning: token pasting of ',' and
      __VA_ARGS__ is a GNU extension [-Wgnu-zero-variadic-macro-arguments]
  ...ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE_...
                                                      ^
liblsoda/src/lsoda.c:193:5: warning: C99 forbids conditional expressions with
      only one void side [-Wpedantic]
  ...ERROR("[lsoda] atol = %g is less than 0.\n", atoli);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
liblsoda/src/lsoda_internal.h:18:37: note: expanded from macro 'ERROR'
#define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strd...
                                    ^~~~~~~~~~~~~~~~

(and so on)

With gcc (same flags)

lsoda.c: In function ‘check_opt’:
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:174:3: note: in expansion of macro ‘ERROR’
   ERROR("[lsoda] neq = %d is less than 1\n", ctx->neq);
   ^
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:190:5: note: in expansion of macro ‘ERROR’
     ERROR("[lsoda] rtol = %g is less than 0.\n", rtoli);
     ^
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:193:5: note: in expansion of macro ‘ERROR’
     ERROR("[lsoda] atol = %g is less than 0.\n", atoli);
     ^

[snip]

lsoda.c: In function ‘lsoda’:
lsoda.c:510:76: warning: ISO C99 requires rest arguments to be used [enabled by default]
    hardfailure("[lsoda] illegal common block did you call lsoda_prepare?\n");
                                                                            ^
lsoda.c:510:76: warning: ISO C99 requires rest arguments to be used [enabled by default]
In file included from lsoda.c:72:0:
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:105:2: note: in expansion of macro ‘ERROR’
  ERROR(fmt, ## __VA_ARGS__); \
  ^
lsoda.c:510:4: note: in expansion of macro ‘hardfailure’
    hardfailure("[lsoda] illegal common block did you call lsoda_prepare?\n");
    ^
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:105:2: note: in expansion of macro ‘ERROR’
  ERROR(fmt, ## __VA_ARGS__); \
  ^
lsoda.c:535:6: note: in expansion of macro ‘hardfailure’
      hardfailure("[lsoda] tout = %g behind t = %g. integration direction is given by %g\n",
      ^
lsoda.c:569:66: warning: ISO C99 requires rest arguments to be used [enabled by default]
      hardfailure("[lsoda] itask = 4 or 5 and tcrit behind tout\n");
                                                                  ^
lsoda.c:569:66: warning: ISO C99 requires rest arguments to be used [enabled by default]
In file included from lsoda.c:72:0:
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:105:2: note: in expansion of macro ‘ERROR’
  ERROR(fmt, ## __VA_ARGS__); \
  ^
lsoda.c:569:6: note: in expansion of macro ‘hardfailure’
      hardfailure("[lsoda] itask = 4 or 5 and tcrit behind tout\n");
      ^
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:105:2: note: in expansion of macro ‘ERROR’
  ERROR(fmt, ## __VA_ARGS__); \
  ^
lsoda.c:596:6: note: in expansion of macro ‘hardfailure’
      hardfailure("[lsoda] ewt[%d] = %g <= 0.\n", i, _C(ewt)[i]);
      ^
lsoda.c:624:71: warning: ISO C99 requires rest arguments to be used [enabled by default]
      hardfailure("[lsoda] tout too close to t to start integration\n ");
                                                                       ^
lsoda.c:624:71: warning: ISO C99 requires rest arguments to be used [enabled by default]
In file included from lsoda.c:72:0:
lsoda_internal.h:18:53: warning: ISO C forbids conditional expr with only one void side [-Wpedantic]
 #define ERROR(fmt, ...) (ctx->error?free(ctx->error):1, ctx->error=_strdup_printf("EE:" fmt " @(%s:%d)", ## __VA_ARGS__, __FILE__, __LINE__))
                                                     ^
lsoda.c:105:2: note: in expansion of macro ‘ERROR’
  ERROR(fmt, ## __VA_ARGS__); \
  ^
lsoda.c:624:6: note: in expansion of macro ‘hardfailure’
      hardfailure("[lsoda] tout too close to t to start integration\n ");
      ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions