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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:38:25+00:00 2026-06-17T12:38:25+00:00

I have some header file that was written for use in a C99 program.

  • 0

I have some header file that was written for use in a C99 program. This header includes all the function definitions, and is not paired with a source file. I am including it in a C++ file.

My C++ compiler flags include -pedantic -std=c++11, which gives me various warnings in the header file such as “ISO C++ forbids compound literals”, and “ISO C++ forbids variable length arrays”. Obviously the C++ compiler is treating the C99 code as C++. Two questions:

  1. Is this a potential problem when trying to write code that will run correctly on various platforms using different compilers?
  2. What is a good way to resolve the warnings, and produce standard conforming code? I was thinking of making a precompiled header file using gcc, but don’t know enough about the process to be assured that I am not going to have unintended consequences from included a C precompiled header in a C++ source.

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-06-17T12:38:26+00:00Added an answer on June 17, 2026 at 12:38 pm

    To include a pure C header file(*) in a C++ project, you should wrap the include statement in an extern "C" block:

    // C++
    extern "C" {
    // C-code goes here
    #include "foo.h"
    }
    

    This is because C++ performs name mangling on all function names to make overloading work. C doesn’t use name mangling, so C++ parses C function signatures with name mangling.

    Please note that extern "C" doesn’t put the compiler into “C-mode” (there is no such mode but you might falsely think of this instruction as such), it doesn’t mangle the function names (+ changes the calling convention and forbids overloading; thanks for doomster for pointing these things out).

    However, it shouldn’t be a problem if you are including a header only (with inline implementations), since this name mangling will only be a problem when you link the C source file or library against your C++ project, since the function names are different in this case.

    This being said, you should use the common subset of C and C++ for the header file, extract and compile the implementations of these functions separately with a C compiler, not C++. Then, you (hopefully) can link both parts together. A lot of C libraries already have headers which are compatible with C++, so this is a common procedure.

    (*): Some header files are already made to be compatible with both languages C and C++ by using the common subset of language features plus wrapping everything in a conditional extern "C" block. For such headers, you should not use this method, but only for the ones which don’t have such a block in it.

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

Sidebar

Related Questions

I have a header file that has some static variables for all of my
I have this header file, zeeheader.h, and I wrote some classes in it, I'm
I have an XML Template file. This file contains a header and some predefined
I have written a generic CSV file reader that I'm trying to use to
I have some useful typedefs on a header file called utypes.h. I have decided
I have some basic jquery code sitting in the header of the header file
I have some extern 'd variables in a namespace in a header file, and
I have some problems with header() function. It works and doesn't work at the
I have .dll library with header file written in C++ (no source code available).
I have a code file that has some #ifdefs I would like removed in

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.