|
|
Wide Preprocessor Concatenation
This works fine -- some obvious problems with double underscores and
no compiler optimizations to combine multiple __FILE__ strings.
For other purposes (equally useless) I'd like get a wide version of
__FILE_LINE__ working. I've spent a while trying, but it has me
befuddled.
#include <stdexcept>
#include <iostream>
#define STRINGIZER_HELPER(x) # x
#define STRINGIZER(x) STRINGIZER_HELPER( x )
#define __LINE_FILE__ "[" STRINGIZER( __LINE__ ) "]" __FILE__
int main( int argc, char* argv[] )
{
try
{
throw std::runtime_error( __LINE_FILE__ );
}
catch( std::exception &e )
{
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}
Output:
Execption: [12]foo.cpp
Thanks,
Joshua Boelter
These are my opinions not official opinions of Intel Corp.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Joshua
|
10/28/2003 2:10:46 AM |
|
Joshua Boelter wrote:
> #define __LINE_FILE__ "[" STRINGIZER( __LINE__ ) "]" __FILE__
This doesn't work with every compiler since __LINE__ can expand to an
integer expression like "(_Line + 13)" for example. (VC6?) And if you
don't want portable code you could use a compiler-extension that
provides even better output. (Like __FUNCTION__ and __PRETTY_FUNCTION__
in gcc.)
(And of course I'd prefer to avoid "obvious problems with double
underscores" by using a different name. Why do people like such names
anyway?)
- Paul
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Paul
|
10/28/2003 3:59:00 PM
|
|
In article <3F9D63D0.5060700@intel.com>, Joshua Boelter wrote:
> This works fine -- some obvious problems with double underscores and
> no compiler optimizations to combine multiple __FILE__ strings.
>
> For other purposes (equally useless) I'd like get a wide version of
> __FILE_LINE__ working. I've spent a while trying, but it has me
> befuddled.
<snip>
> #define STRINGIZER_HELPER(x) # x
> #define STRINGIZER(x) STRINGIZER_HELPER( x )
> #define __LINE_FILE__ "[" STRINGIZER( __LINE__ ) "]" __FILE__
<snip>
This seems to work:
#define WIDE_HELPER( x, y ) x ## y
#define WIDE(x) WIDE_HELPER( L, x )
#define WIDE_LINE_FILE L"[" WIDE( STRINGIZER( __LINE__ ) ) \
L"]" WIDE( __FILE__ )
Note that the name "__LINE_FILE__" is reserved for the implementation
since it contains two consecutive underscores. You should choose
another name.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Ben
|
10/29/2003 1:27:27 AM
|
|
In article <bnlib3$f7u$02$1@news.t-online.com>, Paul Kunysch wrote:
> Joshua Boelter wrote:
>
>> #define __LINE_FILE__ "[" STRINGIZER( __LINE__ ) "]" __FILE__
>
> This doesn't work with every compiler since __LINE__ can expand to an
> integer expression like "(_Line + 13)" for example. (VC6?)
<snip>
VC++ 6 has a lot of non-standard "features". That doesn't mean
everyone should work around them. The standard says __LINE__ expands
to a decimal constant and it seems reasonable to expect that when
writing portable code, unless there's some real need to support this
relic.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Ben
|
10/29/2003 1:34:51 AM
|
|
|
3 Replies
299 Views
(page loaded in 0.042 seconds)
|
|
|
|
|
|
|
|
|