Question
What do I need to know when mixing C and C++ code?

Answers

Here are some high points (though some compiler-vendors might not require all these; check with your compiler-vendor's documentation):

You must use your C++ compiler when compiling main() (e.g., for static initialization)

Your C++ compiler should direct the linking process (e.g., so it can get its special libraries)

Your C and C++ compilers probably need to come from same vendor and have compatible versions (e.g., so they have the same calling conventions)

In addition, you'll need to read the rest of this section to find out how to make your C functions callable by C++ and/or your C++ functions callable by C.

BTW there is another way to handle this whole thing: compile all your code (even your C-style code) using a C++ compiler. That pretty much eliminates the need to mix C and C++, plus it will cause you to be more careful (and possibly —hopefully!— discover some bugs) in your C-style code. The down-side is that you'll need to update your C-style code in certain ways, basically because the C++ compiler is more careful/picky than your C compiler. The point is that the effort required to clean up your C-style code may be less than the effort required to mix C and C++, and as a bonus you get cleaned up C-style code. Obviously you don't have much of a choice if you're not able to alter your C-style code (e.g., if it's from a third-party).   Your Comment




More Software Questions..
What is the inputsplit in map reduce software?

What is software configuration management?

What Is Java Api For Xml-based Rpc (jax-rpc)?

How can you implement fine-grained auditing?

What is IBM’s simple explanation for Big Data’s four critical features?

What is static synchronized method in JDBC API? Give an example?

What does the NULLIF function do?

What happens if a start method is not invoked and the run method is directly invoked?

Should we override finalize method

what is the difference between mysql_fetch_array and mysql_fetch_object?

How will XML affect my document links?

Why to use Style Sheets?

What are Filters in MVC?

Can you explain Application layer in OSI model?

How to define new testplan attributes?

What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?

Which oracle package is used to manage the oracle lock management services?

What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?

What is marker interface?

What types of partitioning are there for BW?



Search
Can you Answer!!
  • Q Do you know what is an accrual?
  • Q A Cruciverbalist is interested in what
  • Q How viewmodel first construction approach leverages the capabilities of implicit data templates in wpf?
  • Q In the 11th Plan the government has invited proposals to set up how many Food parks?
  • Q When Krishna was accidentally killed by Jara, Vishwakarma on instruction from Vishnu started building an image with Krishna’s bones which he placed inside the image. The image however could not be completed and is therefore worshipped in its unfinished form. Which idol are we talking about ?
  • Q What are the differences between quality control and quality assurance?
  • Q Who of the following held the Office of the Vice President of India for two full terms?
  • Q Have you ever sleepwalked?
  • Q What is the function mysql_pconnect() usefull for?
  • Q On what basis name node distribute blocks across the data nodes?
  • Q Anyone with an experience of tannins isolation by column chromatography?