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

  • Home
  • SEARCH
  • 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 6245957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:08+00:00 2026-05-24T12:36:08+00:00

Our C/C++ project is using a new internal script that liberally wraps every function

  • 0

Our C/C++ project is using a new internal script that liberally wraps every function in SWIG to make available to python scripts. It chokes on our logger function since SWIG cannot wrap variadic functions well.

So I decided to hide the variadic functionality in a macro that SWIG will never trip over, shown in a simplified example below:

#include <iostream>

void LogPrint(char *file, int line, char* msg)
{
    std::cout << file << ":" << line;
    std::cout << " [ " << msg << " ] ";
    std::cout << std::endl;
}

#define MAX_LOG 256

#define LogPrintf(msg, args...) \
{ \
    char *msg_buffer = new char[MAX_LOG]; \
    snprintf(msg_buffer, MAX_LOG, msg, ##args); \
    Log(__FILE__, __LINE__, msg_buffer); \
    delete [] msg_buffer; \
}

main()
{
    LogPrintf("%s = %f", "tau", 6.28318);
    LogPrintf("%s = %f", "pi", 3.14159);
}

Is this okay? Are there better solutions to this problem? Thanks.

  • 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-05-24T12:36:09+00:00Added an answer on May 24, 2026 at 12:36 pm

    Python makes it trivial to assemble formatted strings within Python, so I would just offer the simple “give me a string and I log it” error.

    For the general case, though, you might consider:

    1) boost::format

    2) emulating the iostream interface by creating a class that holds a std::stringstream member, overloading operator<< to forward to the stringstream’s operator<<, and then adding some other way to actually log the “buffer” contents (one approach is to log in the destructor of the object – making it non-copyable is probably a good idea – so you can do something like Logger() << "foo" << bar; – the temporary object lifetime is extended to the end of the line, the operator overloads build up the buffer contents, and then the dtor runs and outputs the .str() of the stringstream to whereever).

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

Sidebar

Related Questions

Our issue is that our project has files being downloaded using wget to the
I am working on a new Oracle ADF project, that is using Oragle 10g
We are currently using unit tests to test our project. We have the majority
I'm currently using VS2005 Profesional and .NET 2.0, and since our project is rather
We are preparing to develop an enterprise Human Resources Project using ASP.NET and our
Despite an earlier question ( asked here ), our project is constrained to using
In a project our team is using object lists to perform mass operations on
I just added xUnit to our test project (for the Asserts, we're still using
Currently, we're using the following version numbering scheme for our C# winforms project: Major
The project I'm working is using n-tier architecture. Our layers are as follows: Data

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.