__FILE__,__LINE__,__FUNCTION__ macros

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neo

    __FILE__,__LINE__,__FUNCTION__ macros

    Hi Friends,
    I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
    component in my class.
    In debug build I gets all information. I tried with release mode also
    and it works. But I want to verify that will I able to get this
    information at any kind of build with all possible optimizations?

    Regards
    Vikram S

  • Ian Collins

    #2
    Re: __FILE__,__LINE __,__FUNCTION__ macros

    Neo wrote:
    Hi Friends,
    I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
    component in my class.
    In debug build I gets all information. I tried with release mode also
    and it works. But I want to verify that will I able to get this
    information at any kind of build with all possible optimizations?
    >
    Sounds like a tool issue rather than a C++ one, try a group dedicated to
    your compiler.

    --
    Ian Collins.

    Comment

    • Pete Becker

      #3
      Re: __FILE__,__LINE __,__FUNCTION__ macros

      Neo wrote:
      Hi Friends,
      I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
      component in my class.
      In debug build I gets all information. I tried with release mode also
      and it works. But I want to verify that will I able to get this
      information at any kind of build with all possible optimizations?
      >
      __FILE__ and __LINE__ are always valid, and their meanings are specified
      by the C++ standard. If a compiler switch disables them, the compiler
      doesn't conform to the language definition when that switch is used.

      __FUNCTION__ is not specified by the standard. You'll have to look at
      your compiler's documentation to figure out what it does and when it
      does it.

      --

      -- Pete
      Roundhouse Consulting, Ltd. (www.versatilecoding.com)
      Author of "The Standard C++ Library Extensions: a Tutorial and
      Reference." (www.petebecker.com/tr1book)

      Comment

      • =?iso-8859-1?q?Erik_Wikstr=F6m?=

        #4
        Re: __FILE__,__LINE __,__FUNCTION__ macros

        On Dec 21, 11:05 am, "Neo" <vikram.su...@g mail.comwrote:
        Hi Friends,
        I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
        component in my class.
        In debug build I gets all information. I tried with release mode also
        and it works. But I want to verify that will I able to get this
        information at any kind of build with all possible optimizations?
        __FUNCTION__ is not part of the C++ standard, but __LINE__ and __FILE__
        are. Notice however that the value of __FILE__ can be either the
        relative path (name of file) or the absolute path to the file at
        compile time, or perhaps something in between.

        --
        Erik Wikström

        Comment

        • BobR

          #5
          Re: __FILE__,__LINE __,__FUNCTION__ macros


          Pete Becker wrote in message ...
          >Neo wrote:
          >Hi Friends,
          > I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
          >component in my class.
          > In debug build I gets all information. I tried with release mode also
          >and it works. But I want to verify that will I able to get this
          >information at any kind of build with all possible optimizations?
          >
          >__FILE__ and __LINE__ are always valid, and their meanings are specified
          >by the C++ standard. If a compiler switch disables them, the compiler
          >doesn't conform to the language definition when that switch is used.
          >
          >__FUNCTION__ is not specified by the standard. You'll have to look at
          >your compiler's documentation to figure out what it does and when it
          >does it.
          If the compiler is C99 complient, you can use '__func__' [1].

          [1] - ref: GCC docs. (Some minor restrictions on concatenation.)
          --
          Bob R
          POVrookie


          Comment

          • Pete Becker

            #6
            Re: __FILE__,__LINE __,__FUNCTION__ macros

            BobR wrote:
            >
            If the compiler is C99 complient, you can use '__func__' [1].
            >
            --

            -- Pete
            Roundhouse Consulting, Ltd. (www.versatilecoding.com)
            Author of "The Standard C++ Library Extensions: a Tutorial and
            Reference." (www.petebecker.com/tr1book)

            Comment

            • Pete Becker

              #7
              Re: __FILE__,__LINE __,__FUNCTION__ macros

              BobR wrote:
              Pete Becker wrote in message ...
              >>
              >__FUNCTION__ is not specified by the standard. You'll have to look at
              >your compiler's documentation to figure out what it does and when it
              >does it.
              >
              If the compiler is C99 complient, you can use '__func__' [1].
              >
              That's true if you're compiling C, but the C99 standard doesn't tell you
              what __func__ does in a C++ member function, nor in a template function.

              [1] - ref: GCC docs. (Some minor restrictions on concatenation.)
              As I said: you'll have to look at your compiler's documentation. <g>

              --

              -- Pete
              Roundhouse Consulting, Ltd. (www.versatilecoding.com)
              Author of "The Standard C++ Library Extensions: a Tutorial and
              Reference." (www.petebecker.com/tr1book)

              Comment

              • BobR

                #8
                Re: __FILE__,__LINE __,__FUNCTION__ macros


                Pete Becker wrote in message ...
                >BobR wrote:
                >Pete Becker wrote in message ...
                >>__FUNCTION_ _ is not specified by the standard. You'll have to look at
                >>your compiler's documentation to figure out what it does and when it
                >>does it.
                >>
                >If the compiler is C99 complient, you can use '__func__' [1].
                >
                >That's true if you're compiling C, but the C99 standard doesn't tell you
                >what __func__ does in a C++ member function, nor in a template function.
                >
                >[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
                >
                >As I said: you'll have to look at your compiler's documentation. <g>
                I just know it works in GCC g++ without turning on any special flags or
                includes(yeah, some are 'automatic' <g>).

                Maybe someone with a faster access than I can try this on Comeau?:

                // ------------------------------------
                #include <iostream // #include <ostream>
                void Test( std::ostream &cout ){
                cout<<"\n_____[ "<<__func__ <<" ]_____"<<std::en dl;
                // ------------------------------------
                cout<<"_____[ "<<__func__ <<" ]__End\n"<<std:: endl;
                return;
                }

                int main(){
                Test( std::cout );
                return 0;
                }
                // ------------------------------------

                Did it make Comeau puke?

                Sure is a handy 'feature' for testing, error output, etc..

                --
                Bob R
                POVrookie


                Comment

                • Tony

                  #9
                  Re: __FILE__,__LINE __,__FUNCTION__ macros


                  "BobR" <RemoveBadBobR@ worldnet.att.ne twrote in message
                  news:mNBih.5428 16$QZ1.367681@b gtnsc04-news.ops.worldn et.att.net...
                  >
                  Pete Becker wrote in message ...
                  >>Neo wrote:
                  >>Hi Friends,
                  >> I am planning to use "__FILE__,__LIN E__,__FUNCTION_ _ " for a logging
                  >>component in my class.
                  >> In debug build I gets all information. I tried with release mode also
                  >>and it works. But I want to verify that will I able to get this
                  >>information at any kind of build with all possible optimizations?
                  >>
                  >>__FILE__ and __LINE__ are always valid, and their meanings are specified
                  >>by the C++ standard. If a compiler switch disables them, the compiler
                  >>doesn't conform to the language definition when that switch is used.
                  >>
                  >>__FUNCTION_ _ is not specified by the standard. You'll have to look at
                  >>your compiler's documentation to figure out what it does and when it
                  >>does it.
                  >
                  If the compiler is C99 complient, you can use '__func__' [1].
                  >
                  [1] - ref: GCC docs. (Some minor restrictions on concatenation.)
                  A problem with the __func__ and __FILE__ macros is that you can't
                  control the formatting. Sometimes you may want just a file name rather
                  than a full path, for example.

                  It's odd that the C99 __func__ macro is not __FUNC__, don't ya think?

                  Tony


                  Comment

                  • BobR

                    #10
                    Re: __FILE__,__LINE __,__FUNCTION__ macros


                    Tony wrote in message ...
                    >
                    >"BobR" wrote in message ...
                    >Pete Becker wrote in message ...
                    >>>__FILE__ and __LINE__ are always valid, and their meanings are specified
                    >>>by the C++ standard. If a compiler switch disables them, the compiler
                    >>>doesn't conform to the language definition when that switch is used.
                    >>>
                    >>>__FUNCTION __ is not specified by the standard. You'll have to look at
                    >>>your compiler's documentation to figure out what it does and when it
                    >>>does it.
                    >>
                    >If the compiler is C99 complient, you can use '__func__' [1].
                    >>
                    >[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
                    >
                    >A problem with the __func__ and __FILE__ macros is that you can't
                    >control the formatting. Sometimes you may want just a file name rather
                    >than a full path, for example.
                    std::string FuncName(__func __);
                    // change 'FuncName' to what you want.
                    >
                    >It's odd that the C99 __func__ macro is not __FUNC__, don't ya think?
                    >Tony
                    If '__func__' was a macro, it might have an all uppercase name.

                    From GCC docs:

                    "
                    __func__ is defined by the ISO standard C99:
                    The identifier __func__ is implicitly declared by the translator
                    as if, immediately following the opening brace of each function
                    definition, the declaration
                    static const char __func__[] = "function-name";
                    appeared, where function-name is the name of the lexically-enclosing
                    function. This name is the unadorned name of the function.

                    By this definition, __func__ is a variable, not a string literal. In
                    particular,
                    __func__ does not catenate with other string literals.
                    In C++, __FUNCTION__ and __PRETTY_FUNCTI ON__ are variables,
                    declared in the same way as __func__.
                    "

                    --
                    Bob R
                    POVrookie


                    Comment

                    Working...