C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wide Preprocessor Concatenation

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Joshua Boelter
Guest





PostPosted: Tue Oct 28, 2003 2:10 am    Post subject: Wide Preprocessor Concatenation Reply with 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.

#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





PostPosted: Tue Oct 28, 2003 3:59 pm    Post subject: Re: Wide Preprocessor Concatenation Reply with quote



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





PostPosted: Wed Oct 29, 2003 1:27 am    Post subject: Re: Wide Preprocessor Concatenation Reply with quote



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





PostPosted: Wed Oct 29, 2003 1:34 am    Post subject: Re: Wide Preprocessor Concatenation Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.