Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. log file

log file

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Ed01
    wrote on last edited by
    #1

    Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this : static void write(char* str,...); What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this : #ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var); But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, Ed

    S D 2 Replies Last reply
    0
    • E Ed01

      Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this : static void write(char* str,...); What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this : #ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var); But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, Ed

      S Offline
      S Offline
      Serge Krynine
      wrote on last edited by
      #2

      #ifdef _DEBUG #define TEST test #else //#define TEST #define TEST 0 #endif void test(int, ...) { std::cout << "Hello, World from test() \n"; } int _tmain(int argc, _TCHAR* argv[]) { TEST(5, std::cout << "Hellow, World from _tmain! \n"); return 0; } Note that if #define TEST in Release mode, the test() function will never get called, but its parameters are get evaluated; so if you do not want this side effect, use: #define TEST 0 Regards, Serge

      1 Reply Last reply
      0
      • E Ed01

        Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this : static void write(char* str,...); What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this : #ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var); But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, Ed

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        One solution:

        static void write(char* str,...)
        {
        #ifdef _DEBUG
        write to log file here
        #endif
        }

        Now all of the calls to write() can remain untouched.


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        J 1 Reply Last reply
        0
        • D David Crow

          One solution:

          static void write(char* str,...)
          {
          #ifdef _DEBUG
          write to log file here
          #endif
          }

          Now all of the calls to write() can remain untouched.


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          The following was based on how it is done in MFC (Afx.h):

          // MyTrace.h

          #ifndef __MYTRACE_H__
          #define __MYTRACE_H__

          void MyTrace(int nLevel, LPCTSTR pFmt, ...);
          #ifdef _DEBUG
          #define MYTRACE MyTrace
          #else
          #define MYTRACE 1 ? ((void)0) : MyTrace
          #endif

          #endif // __MYTRACE_H__

          INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

          D 1 Reply Last reply
          0
          • J John R Shaw

            The following was based on how it is done in MFC (Afx.h):

            // MyTrace.h

            #ifndef __MYTRACE_H__
            #define __MYTRACE_H__

            void MyTrace(int nLevel, LPCTSTR pFmt, ...);
            #ifdef _DEBUG
            #define MYTRACE MyTrace
            #else
            #define MYTRACE 1 ? ((void)0) : MyTrace
            #endif

            #endif // __MYTRACE_H__

            INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Yes, that is another way.


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            E 1 Reply Last reply
            0
            • D David Crow

              Yes, that is another way.


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              E Offline
              E Offline
              Ed01
              wrote on last edited by
              #6

              ok, I'll try that. In fact the idea is not to include the parameters in the define... What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle ;) thanks Ed

              D 1 Reply Last reply
              0
              • E Ed01

                ok, I'll try that. In fact the idea is not to include the parameters in the define... What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle ;) thanks Ed

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Ed01 wrote: What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle The function gets called the same in release mode as it is in debug mode. The only difference is that the body of the function is "missing" in debug mode.


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups