Unicode and __FILE__

__LINE__ and __FILE__ allow your code to access its own line number and source file name and is pretty much intended for debugging purposes.

Funny thing is, in a unicode world, __FILE__ stubbornly remains good old fashioned 8-bit char, since it simply represents a literal string e.g. “MyFile.cpp”.

So in unicode land you can make life easy for yourself with a few macros :-


#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#define __WIDEFILE__ WIDEN(__FILE__)

Now, the keen eyed amongst you may be thinking whats the point of the second macro – why not dispense with WIDEN2(x) and use


#define WIDEN(x) L ## x
#define __WIDEFILE__ WIDEN(__FILE__)

Well, cos that doesn’t work !

Leave a Reply