Thread: L__FILE__ doesn't work...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    L__FILE__ doesn't work...

    Hi,
    I'm wondering how the L macro (or whatever it is) works?
    It works fine with text in quotes like: L"Hello world", but if I want to apply it to another macro like this: L__FILE__ the compiler can't figure out what I'm trying to do.
    I can get it to work using: _T( __FILE__ ), but that's a little ugly and non-standard.
    I tried: L( __FILE__ ), but then the compiler doesn't know what L is...
    Is there a way to make it work with L?

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    I just did a quick google, and I found that the L macro is for making string literals into unicode.

    How do you logically justify prefixing __FILE__ with the L macro?

    What is that supposed to do?

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by IceDane View Post
    I just did a quick google, and I found that the L macro is for making string literals into unicode.

    How do you logically justify prefixing __FILE__ with the L macro?

    What is that supposed to do?
    __FILE__ is an ASCII string, but I'm passing it to a function that takes UNICODE strings, so I need something like the L or _T() macro to do it...

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    L isn't a macro, it's a grammatical prefix (just like 1.0f -- the f isn't a macro), so it can only appear before a string literal. There may be a way to do some preprocessor trickery here, but I'm not seeing anything good off the top of my head.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Why not just put a space:

    Code:
    L __FILE__
    Or does that not work?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The preprocessor will recognize __FILE__ now, but you can't have a space between L and "xyz" to have a long string.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by tabstop View Post
    The preprocessor will recognize __FILE__ now, but you can't have a space between L and "xyz" to have a long string.
    So then why not a macro:

    Code:
    #define MY_L(x) L##x
    That would allow for the two-stage expansion of __FILE__ to "blah.c" and then L##"blah.c" --> L"blah.c"

    EDIT: Doh, that's basically what Dave posted a link to (except the linked way actually works )
    Last edited by brewbuck; 04-07-2008 at 10:26 AM.

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Dave_Sinkula View Post
    So I need 2 macros... strange. OK thanks.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, the first macro serves to "resolve" __FILE__ into "blah.c" or such, then the second does L + "blah.c".

    It's a "classic" trick.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM