Stringified __LINE__

From: Michael B Allen (mba2000_at_ioplex.com)
Date: 02/28/05

  • Next message: Chris Torek: "Re: open vs. fopen"
    Date: Mon, 28 Feb 2005 02:38:17 -0500
    
    

    How does the following work and is it portable?

    /*
      this uses a little trick to allow __LINE__ to be stringified
    */
    #define _STRING_LINE_(s) #s
    #define _STRING_LINE2_(s) _STRING_LINE_(s)
    #define __LINESTR__ _STRING_LINE2_(__LINE__)
    #define __location__ __FILE__ ":" __LINESTR__

    Result:

      printf("%s", __location__);

    becomes:

      printf("%s", "t0.c" ":" "27");

    and prints:

      t0.c:27

    Mike

    PS: macros found in talloc.h at junkcode.samba.org


  • Next message: Chris Torek: "Re: open vs. fopen"