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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:27:40+00:00 2026-06-10T11:27:40+00:00

I have an error reporting functionality in my little C library I’m writing. I

  • 0

I have an error reporting functionality in my little C library I’m writing. I want to provide an errorf function in addition to the plain error function to allow embedding information in error messages easily.

/*
 * Prints a formatted error message. Use it as you would use 'printf'. See the
 * 'sio_error' function.
 */
void sio_errorf(const char *format, ...) {
    // Print the error prefix                           
    if (g_input == STDIN) fputs("error: ", stderr);
    else fprintf(stderr, "%s: ", g_progname);

    // Pass on the varargs on to 'vfprintf'. 
    va_list arglist;
    va_start(arglist, format);
    // This may produce the following warning -- ignore it:
    //     warning: format string is not a string literal
    vfprintf(stderr, format, arglist);
    va_end(arglist);
    fputc('\n', stderr);
}

The problem is, I get this warning (compiling with clang 4.0 with the -Weverything switch):

warning: format string is not a string literal

I understand why doing this would be bad. Is there any way I can get rid of this warning? Can I somehow enforce that the format argument sio_errorf be a string literal, so that the compiler knows that it always will be, and that I’m simply passing it on?

I know I can use -Wno-format-nonliteral, but only if other people are going to manually compile it too, they won’t do that. I’d rather something in the source code that silences the warning.

Ideally I would still get the warning if the string I passed to sio_errorf actually isn’t a literal, but I’m not sure if that’s possible.

  • 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-10T11:27:42+00:00Added an answer on June 10, 2026 at 11:27 am

    If you’re using GCC or one of its relatives, try an attribute on the declaration:

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

    To add the attribute to a definition, you can use this:

    __attribute__((format(printf, 1, 2)))
        static void sio_errorf(const char *format, ...) {
          ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a library that deals with many aspects of error reporting. I have
I have a project where in my error reporting I want to send a
I have this consumer targeted application that has built in error reporting. Sometimes I
I am trying to implement Error Reporting and Recovery in JavaCC grammar I have
We have error reporting on our website so we're notified via e-mail whenever errors
I'm trying to provide reporting functionality on a typical restaurant type database. I describe
I'd like to have better error page reporting in Google Analytics. Currently, if someone
My objective is to have an IDE with JS syntax error reporting and a
I have set error reporting in my development environment to E_STRICT by adding to
I have strict error reporting. I have to use isset and it make me

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.