Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

__LINE__ in macros

0 views
Skip to first unread message

Andy Venikov

unread,
Apr 16, 2003, 10:20:04 AM4/16/03
to
First of all, I'm sorry if this topic has been covered before, but I'm new
to this group and after 20 minutes of search on google groups I couldn't find
the trehad.

Anyway, my question is why doesn't __LINE__ expand correctly when used in macros?
For example, the following code should declare a different variable each time
ANONYMOUS_VARIABLE is used:

#define REALLY_CONCATENATE(str1, str2) str1##str2
#define CONCATENATE(str1, str2) REALLY_CONCATENATE(str1, str2)
#define ANONYMOUS_VARIABLE CONCATENATE(anonymous, __LINE__)

//Use it like this:
int ANONYMOUS_VARIABLE; //declares variable named anonymous0
int ANONYMOUS_VARIABLE; //declares variable named anonymous1

It works fine in just any other compiler (gcc and Como to name a few)

But on VC60 (SP5) it fales to expand __LINE__ and instaead of
two variables "anonymous0" and "anonymous1" I get redefinition
of plain "anonymous"

Is there a workaround?

Thank you,
Andy.

Hendrik Schober

unread,
Apr 16, 2003, 11:17:42 AM4/16/03
to
"Andy Venikov" <avNeOni...@nospam.attbi.com> wrote:
> [problems with '__LINE__']

I use this everyday:

#define STRINGIZE( L ) #L
#define MAKESTRING( M, L ) M(L)
#define MESSAGE_ORIGIN __FILE__ "(" MAKESTRING( STRINGIZE, __LINE__ ) "): "

#pragma message ( MESSAGE_ORIGIN "QED" )

> Thank you,
> Andy.

Schobi

--
Spam...@gmx.de is never read
I'm Schobi at suespammers org

Andy Venikov

unread,
Apr 16, 2003, 3:52:05 PM4/16/03
to
What version of visual studio are you using?
Because in my case your code doesn't work, __LINE__
is not expanded.
I'm using MSVC6.0 SP5

Andy Venikov

unread,
Apr 16, 2003, 4:10:09 PM4/16/03
to
O.K., I found the problem - it's a Microsoft Compiler's bug.
Look at the Knowledge Base article 199057

http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b199057

Hendrik Schober

unread,
Apr 17, 2003, 4:36:33 AM4/17/03
to
"Andy Venikov" <avNeOni...@nospam.attbi.com> wrote:
> What version of visual studio are you using?
> Because in my case your code doesn't work, __LINE__
> is not expanded.
> I'm using MSVC6.0 SP5

So am I.

> [...]

0 new messages