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 990117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:53:58+00:00 2026-05-16T05:53:58+00:00

Accidential use of classes inside of c style typeless variable arguments list is a

  • 0

Accidential use of classes inside of c style typeless variable arguments list is a common error source.
Example:

class MyString {
    public:
    char *pChars;
    int Length;

    MyString(char *pChars) {
        this->pChars = pChars; 
        Length = strlen(pChars); 
        } };

int main() {
    MyString s1("Bla1"), s2("Bla2");
    printf("%s%s", s1, s2); // This does not but should give a compiler warning/error!
    return 0; }

The printf call there receives the two s objects by value. that means all of their members are simply memory copied. But they are interpreted a simple char pointers. Result is a runtime error of course.

I am not asking for a solution to this, but I would like to have something I could add to my class so that the compiler warns me about it or gives an error.

Already tried to declarate but not implement a copy constructor. But it seems that no copy constructor is called. 🙁

Please just answer to the question in the title. I do not need a discusson of why you should not use printf or these variable arguments lists – know that.

Thanks for your time.

  • 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-16T05:53:58+00:00Added an answer on May 16, 2026 at 5:53 am

    Decent compilers (like gcc) check whether printf arguments match format specifiers in format string.

    Just do not forget to add -Wformat or -Wall command line option.

    http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

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

Sidebar

Related Questions

This is a very simple example where accessing directly could be dangerous class Something{
I use templated helpers in an ASP.NET MVC 3 project. One display template had
(I am a relative newcomer to TortoiseHg, so bear with me :-) I use
I've designed a C# game that makes use of an Access .mdb database file
In my C# client application, I use XSLT to transform XML into HTML. I
in my code I use HANDLE s from windows.h . They are used like
My plan is to use git to keep track of changes in /etc but
I'd like to use the django admin to produce a read-only view of an
I have written a static library to re-use some code between iOS projects, let's
I cannot delete/drop a crashed Innodb table. I get the following error: ERROR 1051

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.