title: Why does va_start fail?
body: <p>I want to create some logging, and i made a class. However i have some problem with passing the arguments to it.</p>
  
  <p>Class:      </p>
  
  <pre><code>namespace debug
  {
      class log
      {
          private:    // Members
              const std::string context;
              int Type;
          public:     // Methods
              void message( int Type, const std::string&amp; message, ... );
  
          public:     // Constructor, Destructor
              log( const std::string&amp; context, int Type );
              ~log();
      };//class log
  }//namespace debug     
  
  namespace debug
  {
      void log::message( int Type, const std::string&amp; message, ... )
      {
          va_list args;
          int len;
  
          char    *buffer;
  
          va_start( args, message );
  
          len = _vscprintf( message.c_str(), args ) + 1; // _vscprintf doesn't count terminating '\0'
          buffer = ( char* )malloc( len * sizeof( char ) );
  
          vsprintf_s( buffer, len, message.c_str(), args );
  
          va_end( args );
  
      }//log::message
  }//namespace debug
  </code></pre>
  
  <p>I have two macros defined:     </p>
  
  <pre><code>#define DEBUG_METHOD( Type )  debug::log _debugLog( __FUNCTION__, Type );
  #define DEBUG_MESSAGE( Type, debug_message, ... ) { _debugLog.message( Type, debug_message, ##__VA_ARGS__ ); }
  </code></pre>
  
  <p>And i use them in a Function like this:</p>
  
  <pre><code>BOOL test( BOOL *bTestVal)
  {
     DEBUG_METHOD( INFO );
     DEBUG_MESSAGE( INFO, "Argument1 = '%s'", BoolToString( ( BOOL )*bTestVal) );
  
         //here comes some work...
  }
  </code></pre>
  
  <p>Unfortunately i always get an error. This line <code>len = _vscprintf( message.c_str(), args ) + 1;</code> always throws an error. I think <code>va_start</code> is causing this, becasue <code>args</code> has a value of <code>+        args    0x0052eed8 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ... char *
  </code></p>
  
  <p>Could someone please help me what i am doing wrong?</p>
  
  <p>Thanks in advance!</p>