#define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__,
__LINE__, #x); }
MSVC7 gives an error: "error C2014: preprocessor command must start as first
nonwhite space". 8 5108
"Siemel Naran" <Si*********@REMOVE.att.net> wrote... #define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__, __LINE__, #x); }
MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
If you want to span a macro over several lines of code, you _have_ to end
all
but the last with a \:
#define EXPECT_ASSERT(x) \
{ \
if (!x) \
expect_assert(localVariable, \
__FILE__, \
__LINE__, \
#x \
); \
}
V
Siemel Naran wrote: #define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__, __LINE__, #x); }
MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
Add a backslash at the end of the first line.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
Pete Becker <pe********@acm.org> wrote in message Siemel Naran wrote: #define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__, __LINE__, #x); }
MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
Add a backslash at the end of the first line.
Thanks. I guess by end of the first line you mean before the #x
(because different browsers/newsreaders page wrap differently). The
code below is two lines: line 1 starts with "#define" and ends with
"__LINE__, \", and line 2 starts with #x.
#define EXPECT_ASSERT(x) { if (!(x)) expect_assert(outputArgs,
__FILE__, __LINE__, \
#x); }
Anyway, is this behavior standard or Microsoft specific?
"Victor Bazarov" <v.********@comAcast.net> "Siemel Naran" <Si*********@REMOVE.att.net> wrote...
#define EXPECT_ASSERT(x) \ { \ if (!x) \ expect_assert(localVariable, \ __FILE__, \ __LINE__, \ #x \ ); \ }
Thanks. This works, in addition to the suggestion Pete gave. Out of
curiosity, if have a macro
#define SOME_MACRO myfunction(__LINE__)
and we rewrite it as
#define SOME_MACRO myfunction( \
__LINE__)
will the line number passed to myfunction be the same in the following
program:
int main() { // line 10
SOME_MACRO; // will this call myfunction(10) or myfunction(11)?
}
Thanks.
Siemel Naran wrote: "Victor Bazarov" <v.********@comAcast.net>
"Siemel Naran" <Si*********@REMOVE.att.net> wrote...
#define EXPECT_ASSERT(x) \ { \ if (!x) \ expect_assert(localVariable, \ __FILE__, \ __LINE__, \ #x \ ); \ }
Thanks. This works, in addition to the suggestion Pete gave. Out of curiosity, if have a macro
#define SOME_MACRO myfunction(__LINE__)
and we rewrite it as
#define SOME_MACRO myfunction( \ __LINE__)
will the line number passed to myfunction be the same in the following program:
int main() { // line 10 SOME_MACRO; // will this call myfunction(10) or myfunction(11)? }
Why don't you just try it? :-)
Well, concatenation of lines with the \ between them happens _before_ any
macro substitution. Since __LINE__ is a macro, the substitution has to
happen _after_ the concatenation, so the 'SOME_MACRO' example you gave
should be considered as a single line. That's basically how you can make
your macro register where it was placed in the code. Of course it does
*not* prevent you from doing
SOME_MACRO; SOME_MACRO;
and have two calls with the same value at run time, since both macros get
the same __LINE__ substitution.
V
Siemel Naran wrote: Pete Becker <pe********@acm.org> wrote in message
Siemel Naran wrote:
#define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__, __LINE__, #x); }
MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
Add a backslash at the end of the first line.
Thanks. I guess by end of the first line you mean before the #x (because different browsers/newsreaders page wrap differently). The code below is two lines: line 1 starts with "#define" and ends with "__LINE__, \", and line 2 starts with #x.
#define EXPECT_ASSERT(x) { if (!(x)) expect_assert(outputArgs, __FILE__, __LINE__, \ #x); }
Anyway, is this behavior standard or Microsoft specific?
The Standard requires that if you want something after # to be interpreted
as a preprocessor directive, there has to be nothing between the beginning
of the line and the #, except whitespace. IOW, on any _separate_ line of
code, if the preprocessor sees only whitespace followed by #, it tries to
interpret what follows the # as the directive.
V
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<3w8jd.372421 #define EXPECT_ASSERT(x) \ { \ if (!x) \
Also, we have to use parenthesis around x, as it might be a sentence,
not a simple variable.
if (!(x)) \ na*******@excite.com (Siemel Naran) wrote: MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
The code below is two lines: line 1 starts with "#define" and ends with > "__LINE__, \", and line 2 starts with #x.
#define EXPECT_ASSERT(x) { if (!(x)) expect_assert(outputArgs, __FILE__, __LINE__, \ #x); }
Anyway, is this behavior standard or Microsoft specific?
This has got to be a compiler bug. I guess you will get the
same result if you write:
#define foo \
#x)
FWIW do you get an error if you go:
#define foo \
#error Error! This discussion thread is closed Replies have been disabled for this discussion. Similar topics
699 posts
views
Thread by mike420 |
last post: by
|
8 posts
views
Thread by Rich Grise |
last post: by
|
2 posts
views
Thread by Steven T. Hatton |
last post: by
|
26 posts
views
Thread by GS |
last post: by
|
9 posts
views
Thread by Tin Gherdanarra |
last post: by
|
14 posts
views
Thread by Henry Townsend |
last post: by
|
1 post
views
Thread by Ravi |
last post: by
|
16 posts
views
Thread by Chuck |
last post: by
|
2 posts
views
Thread by babakandme |
last post: by
| | | | | | | | | | |