assert(x) and '#define ASSERT(x) assert(x)'

From: Alex Vinokur (alexvn_at_big-foot.com)
Date: 11/25/04


Date: Thu, 25 Nov 2004 10:33:22 +0200

Here are two programs.

--- foo1.c ---
#include <assert.h>
#define FOO 10
int main()
{
  assert (15 < FOO);
  return 0;
}
-------------

--- foo2.c ---
#include <assert.h>
#define FOO 10
#define ASSERT(x) assert(x)
int main()
{
  ASSERT (17 < FOO);
  return 0;
}
-------------

// gcc 3.3.3

$ gcc -W -Wall foo1.c -o a1
// No errors/warnings

$ gcc -W -Wall foo2.c -o a2
// No errors/warnings

$ ./a1
assertion "15 < FOO" failed: file "foo1.c", line 5
Aborted (core dumped)

$ ./a2
assertion "17 < 10" failed: file "foo2.c", line 6
Aborted (core dumped)

$ gcc -dM -E foo1.c | grep ASSERT
// No output

$ gcc -dM -E foo2.c | grep ASSERT
#define ASSERT(x) assert(x)

-------------------------------------
Why does a1 print "15 < FOO", but not "15 < FOO"?
Why does a2 print "17 < 10", but not "17 < FOO"?

-- 
 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn


Relevant Pages

  • Re: [C] strcat() question (ongoing)
    ... > At the machine level, yes, basically (depending on your definition ... We can only "PUT" data in / or assign data to variables such as an int or ... foo is an object? ... > house and look on the microwave. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: call of variadic function
    ... arguments that should be passed to this function are of type int. ... You call foo with more arguments than are ... which is the standard way to access arguments of a variadic function ... Here the else clause of my sentence specifies one of the numerous non- ...
    (comp.lang.c)
  • Re: RISC OS modules with stock gcc?
    ... int bar; ... DCD &ff000004 ... IMPORT bar ... EXPORT foo ...
    (comp.sys.acorn.programmer)
  • Re: Cannot convert to `int in initialization
    ... Foo foo1, foo2; ... foo.cpp: In function `int main': ... for.cpp:5: error: expected unqualified-id before numeric constant ... alex DOT vinokur AT gmail DOT com ...
    (comp.lang.cpp)
  • Re: call of variadic function
    ... arguments that should be passed to this function are of type int. ... call and the definition of function foo itself does NOT produce any ... which is the standard way to access arguments of a variadic function ... Here the else clause of my sentence specifies one of the numerous non- ...
    (comp.lang.c)