| View previous topic :: View next topic |
| Author |
Message |
Joshua Boelter Guest
|
Posted: Tue Oct 28, 2003 2:10 am Post subject: 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! ]
|
|
| Back to top |
|
 |
Paul Kunysch Guest
|
Posted: Tue Oct 28, 2003 3:59 pm Post subject: Re: Wide Preprocessor Concatenation |
|
|
Joshua Boelter wrote:
| Quote: | #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! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Wed Oct 29, 2003 1:27 am Post subject: Re: Wide Preprocessor Concatenation |
|
|
In article <3F9D63D0.5060700 (AT) intel (DOT) com>, Joshua Boelter wrote:
| Quote: | 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! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Wed Oct 29, 2003 1:34 am Post subject: Re: Wide Preprocessor Concatenation |
|
|
In article <bnlib3$f7u$02$1 (AT) news (DOT) t-online.com>, Paul Kunysch wrote:
| Quote: | 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! ]
|
|
| Back to top |
|
 |
|