My naive suggestion would be to create a new project with precompiled headers disabled, then put in the code that you have written.
This is a discussion on calling C functions from C++ code within the C++ Programming forums, part of the General Programming Boards category; My naive suggestion would be to create a new project with precompiled headers disabled, then put in the code that ...
You can disable precompiled headers for individual source files.
Just select them and select properties, then find yourself into C/C++ and find that precompiled headers option and turn it off.
As I said, it's not really a choice because it's part of a larger project that uses the precompiled header. Some of the other code was written by somebody else.
Put your code into separate files and disable PCH for them.
Alternatively, compile your C source files as C++.
Select only the C files, right-click and select properties.
Excluded from Build: (yes or no)
and the only category available is Configuration Properties, with subcategory General. Usually, to find the option to disable PCH, it's under a subcategory C/C++, which is not available unless I select the entire project. Am I missing something? Perhaps a specific Item Type?
Nevermind, I did a bit more research and found out about the Yc[filename] option. Let me try it out. Thanks.
Actually, that wasn't for what I thought it was. Yc[filename] is something else...
There should be a C/C++ category if you did it right.
Select a source file, right-click, select properties. You did that on a specific file, did you not? Not the solution or anything else?
For the record, /Yc and /Yu are used to use and create PCH; to not use them, you omit those options.
My c code uses math.h, but not cmath. I'll play around with this for a bit and see if I can get it to work. Thanks.Code:cmath(19): error C2061: syntax error : identifier 'acosf'
Found out about the relationship between cmath and math.h (they are basically, in a way, the same. No such thing as cmath.h)
This raises many questions about why I am getting all those syntax errors in cmath...
If you try to include the cmath header in a C file you will probably get quite a few errors. The cmath header file is not the same as math.h. The cmath header file probably includes some overloaded functions that are only available for use in C++. For example my cmath header file has several different abs() functions, one for double, one for float, and one for long doubles. Since C does not allow overloaded functions you would get several errors because of this. Also cmath includes a namespace declaration, and C does not use namespaces, another error.
So you should always use the proper C standard header for a C file, and the proper C++ standard header for a C++ file.
Last edited by jimblumberg; 02-16-2012 at 11:30 PM.
That makes perfect sense. I realized I was including iostream, which is a c++ library. That took away the cmath errors. Now I'm getting other errors, but they're with a different library I'm working with, so it's another story...
Where did you find "your" C code? Are there other files or functions that came with "your" C code? "Your" C code looks to me like it may be part of a larger code base meant to be used as a library, not necessarily a stand alone function.