$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-03-08 04:31:26
> -----Original Message-----
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Wu 
> Yinghui, Freddie
> Hi all,
> 
> I'm observing an interesting problem on MSVC71 regarding the 
> use of __LINE__ with Boost.Preprocessor.
> 
> The code looks like this
> ==== snip ====
> #include <boost/preprocessor/cat.hpp>
> #define UNIQUE_ID   BOOST_PP_CAT(id, __LINE__)
> #define UNIQUE_ID2   BOOST_PP_CAT(id, _MSC_VER)
> int main()
> {
>      int UNIQUE_ID2 = 321;
>      int UNIQUE_ID = 123;
>      bool UNIQUE_ID = false;
> }
> ==== snip ====
> 
> The compiler works fine with UNIQUE_ID2, but not UNIQUE_ID. 
> The only different in them is only the use of __LINE__ 
> instead of _MSC_VER.
What is going wrong?  I tried it on VC7, VC7.1, and VC8, and it appeared to work
correctly on all three versions of the compiler.
> Does anyone on the list has more insight on this issue?
I've seen strange problems related to __LINE__ on VC before, but I can't
remember off the top of my head what the issue was.  (Thinking...)  It has
something to do with the generation of debug information.  Okay, yes, I see the
error that you are getting now.  It only happens in during a debug build.
This is just one of the *many* ways in which VC's preprocessor is wacky.  It
suffices to say it isn't even in the ballpark of implementing the phases of
translation correctly.
> Or, what're the common ways to generate an unique identifier 
> automatically within certain scope?
What do you mean by "certain scope"?  Or, more precisely, given a finite scope
such as that defined by a function, why do you need unique identifiers?  Most of
the time when people want unique identifiers, they want an identifier that is
unique across an entire program or, at minimum, inside a translation unit.
Regards,
Paul Mensonides