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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:28:28+00:00 2026-05-11T20:28:28+00:00

Here is a piece of code: #include <stdio.h> #include <stdarg.h> void MyPrintf(char const* format,

  • 0

Here is a piece of code:

#include <stdio.h>
#include <stdarg.h>

void MyPrintf(char const* format, va_list args);
void MyVariadicPrintf(char const* format, ...);

void MyPrintf(char const* format, va_list args)
{
    vprintf(format, args);
}

void MyVariadicPrintf(char const* format, ...)
{
    va_list args;
    va_start(args, format);
    MyPrintf(format, args);
    va_end(args);
}

int main(int, char*)
{
    MyVariadicPrintf("%s" /* missing 2nd argument */);

    return 0;
}

I’m compiling it with GCC 4.0, running Xcode on Mac OS X Leopard.
-Wformat and -Wmissing-format-attribute are enabled.
This code gives a warning on line 9 (call to vprintf), suggesting that MyPrintf could use the ‘format’ attribute:

function might be possible candidate for ‘printf’ format attribute

So I add the attribute this way (not sure if this is right):

void MyPrintf(char const* format, va_list args) __attribute__((format(printf, 1, 0)));

The previous warning disappears and the same warning now appears on line 16 (call to MyPrintf), suggesting that MyVariadicPrintf could use the ‘format’ attribute.
So I add the attribute this way (pretty sure this is right this time):

void MyVariadicPrintf(char const* format, ...) __attribute__((format(printf, 1, 2)));

And now I get the expected warning on line 22 (call to MyVariadicPrintf):

too few arguments for format

  1. Did I do this right?

  2. I noticed that on MyPrintf declaration, if I delete the attribute part, I’ll still get the wanted warning on line 22. I also noticed that in this attribute part, changing the index from 1 to 2 won’t give any warning or error. Which one is right and what is the goal of the attribute on this function?

  3. If I add the following function MyVariadicPrintfT and call it (specialized with char), I’ll get the warning suggesting to use the ‘format’ attribute on this function. I think it’s impossible because the format argument is dependent on the templated type. Am I right?

     template<typename Type>
     void MyVariadicPrintfT(Type const* format, ...)
     {
         va_list args;
         va_start(args, format);
         MyPrintf(format, args);
         va_end(args);
     }
    

The latest gnu documentation can be found at gnu.org.
Warning Options are in section 3.8 (look for -Wmissing-format-attribute).
Function Attributes are in section 6.30 (look for format (archetype, string-index, first-to-check)).

  • 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-11T20:28:28+00:00Added an answer on May 11, 2026 at 8:28 pm

    The documentation has the answer you need. Particularly:

    1. Yes
    2. The one you have posted is correct (format(printf, 1, 0)). 1 because the format string is parameter 1, 0 because there are no variadic arguments to be checked.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems that I found what I needed myself. So that… May 12, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer BOOL canMakePhoneCalls = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:5555555"]]; May 12, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer Yes, just return the current object (this), and you can… May 12, 2026 at 3:47 pm

Related Questions

I'm a beginner programmer and I'm learning my first language, C. I'm learning mostly
I am writing an application that needs to send data over a network. I
Is there a difference between compiling projects in *nix environments and MS Visual C++?
Still having issues with this problem. Please help if you can. So I am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.