Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:13:32+00:00 2026-06-01T03:13:32+00:00

I am looking to have a portable debug class since i plan to work

  • 0

I am looking to have a portable debug class since i plan to work on the project on various platforms. This class provides methods to write messages through XDebug.WriteLine(“I like number %d”, 7); Which internally redirects the arguments to the system specific method.

This requires me to pass the ellipsis data as a parameter. And here is the problem. It works on integers, but loses floats on pass through.

XDebug::WriteLine("Print numbers %f, %f",1.234, 3.210f);
XDebug::odprintf(L"Print numbers %f, %f",1.234, 3.210f);

outputs

Print numbers 0.000000, 0.000000
Print numbers 1.234000, 3.210000

I am trying to figure out where the arguments get mangled. Would appreciate your help. The entire debug class is below.

#pragma once
#ifndef _XDEBUG_H_
#define _XDEBUG_H_

#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <Windows.h>;

class XDebug
{
public:

    static void __cdecl WriteLine(const char* txt, ...){
        #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)

        int stringSize = MultiByteToWideChar (CP_ACP, 0, txt, -1, NULL, 0);
        wchar_t* buffer = new wchar_t[stringSize];
        MultiByteToWideChar(CP_UTF8 , 0 , txt, -1, buffer, stringSize);

        va_list args;
        va_start(args, txt);
        XDebug::odprintf(buffer,args);

        delete buffer;

        #endif
    }

//private:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    static void __cdecl odprintf(const wchar_t *format, ...){
    wchar_t    buf[4096], *p = buf;
    va_list args;
    int     n;

            va_start(args, format);
            n = _vsnwprintf(p, sizeof buf - 3, format, args); // buf-3 is room for CR/LF/NUL
            va_end(args);

            p += (n < 0) ? sizeof buf - 3 : n;

            while ( p > buf  &&  isspace(p[-1]) )
                    *--p = '\0';

            *p++ = '\r';
            *p++ = '\n';
            *p   = '\0';

            OutputDebugString(buf);
    }
#endif
};

#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:13:34+00:00Added an answer on June 1, 2026 at 3:13 am

    You cannot forward varargs between functions like that, for the same reason that you can’t pass args directly to sprintf (you have to use a special vsprintf).

    I suggest writing an overload of odprintf that takes a va_list object as a parameter. (And to avoid duplication, you could then implement the original odprintf in terms of the new overload.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking to have a database query set all the instance variables in a class:
I have been looking for a portable method to digitally sign arbitrary text which
I'm looking to write a portable filesystem scanner, capable of listing all files on
Im looking to have a common parent function like so void main (param 1,
Im looking to have a login system on my asp.net mvc website and at
I have a text field and am looking to have if be valid for
I am looking to have a SharePoint Extranet Portal setup for my partner clients.
I am looking to have a list of arguments passed across in an a
I'm looking to have it so that if someone enters information in a form,
Hi I'm looking to have an alert banner at the top of page be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.