can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • baumann.Pan@gmail.com

    can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

    where are these macros defined? can I use it a release ver code?

  • Minti

    #2
    Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

    What exactly is your question? You can use __FILE__ and __LINE__ in
    both DEBUG and NON_DEBUG versions. Or was it something else that you
    wanted to ask?

    --
    Imanpreet Singh Arora

    Comment

    • Keith Thompson

      #3
      Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUGdefined?

      baumann.Pan@gma il.com writes:[color=blue]
      > where are these macros defined? can I use it a release ver code?[/color]

      Please include your complete question in the body of your article; not
      all newsreaders show the subject in a useful manner.

      The question was:

      can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

      And the answer is yes. __FILE__ and __LINE__ (along with several
      others) are predefined macros, unconditionally defined by the
      preprocessor.

      There's nothing called "DEBUG" in standard C (though you can define
      something by that name for yourself). (You might be thinking of
      NDEBUG, a macro that can be defined to cause the assert() macro to
      become a no-op.)

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      • leon

        #4
        Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

        A good practise is not to use __FILE__ in production code, as compiler
        converts __FILE__ into const strings, which takes up static memory.

        Comment

        • Walter Roberson

          #5
          Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

          In article <1110580782.184 927.171910@l41g 2000cwc.googleg roups.com>,
          leon <leonli2004@yah oo.com> wrote:
          :A good practise is not to use __FILE__ in production code, as compiler
          :converts __FILE__ into const strings, which takes up static memory.

          ??

          Static memory is going to take no more space than dynamic memory, since
          malloc() returns a pointer that is worst-case aligned (but you could
          calloc() for a less-aligned result.)

          malloc() and friends are going to have the overhead of keeping track of
          the size and location of the allocated chunk, which is going to take
          more space than just storing the string.

          The code to compute __FILE__ on the fly is surely going to take more
          space than the constant string; I'm not sure how you would even write
          such code except by mousing into the debugging symbols for the
          executable, which would be pretty non-portable and would very likely
          take more space than the constant string would.

          The only thing I can see is that if the string were dynamic then you
          could reclaim the space once you have determined you do not need it...
          but figuring out for sure that you will no longer even indirectly or
          through a function pointer call anything from a particular file is
          going to require non-trivial embedded logic that would surely be messy
          and take more space than was saved.

          Perhaps you could expand on your point?
          --
          "No one has the right to destroy another person's belief by
          demanding empirical evidence." -- Ann Landers

          Comment

          • Keith Thompson

            #6
            Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUGdefined?

            "leon" <leonli2004@yah oo.com> writes:[color=blue]
            > A good practise is not to use __FILE__ in production code, as compiler
            > converts __FILE__ into const strings, which takes up static memory.[/color]

            Of course it's going to take up memory. That's what memory is for.

            If you need the value of __FILE__, use it. There's probably no way to
            get the same information that's going to consume less memory.

            Whether you want to use it in production code depends entirely on how
            you want production code to behave. __FILE__ and __LINE__ are
            typically used in error messages like "Something bad happened on line
            42 of foobar.c". If you don't want your production code producing
            messages like that, don't use __FILE__ and __LINE__ (you can use #if
            or #ifdef to eliminate the code that uses it) -- but keep in mind that
            there's a risk in building production and non-production code
            differently.

            --
            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
            We must do something. This is something. Therefore, we must do this.

            Comment

            Working...