views:

54

answers:

2

I'm trying to integrate two projects, and to that end am including header files from one into the other. I'm using visual studio 2008 express.

The line

int E4407B_PPM(int &);

is throwing errors in the new project, but the original project compiles just fine.

The error I'm getting:

error C2143: syntax error : missing ')' before '&'

Any ideas?

Edit: I ended up removing the lines that took parameters in by reference, and just insured that all functions were declared before they were used in the actual source file. I guess it was a C++/C thing.

+2  A: 

You are probably building the second project (or at least the source file) as straight C. Make sure the file has a .cpp extension or that you are forcing a C++ compile (you can use the /TP compile option to do that).

Edit You can specify it for a single file: Right click on the file in the solution explorer and select Properties. Click on the Advanced option under C/C++. Choose "Compile as C++ Code (/TP)" (second option in the page in my version of Visual Studio).

Mark Wilkins
Forcing the whole project to compile as C++ causes many problems in code that isn't mine, and would take a long time to track down and fix. Can I force just the one source file to compile as C++?
Colin DeClue
@Colin: Yes, you can specify that option for a single file. I will add it to the answer. If you do that, you may have link problems due to name mangling/decoration. If so you may need to add some `extern "C"` to appropriate headers.
Mark Wilkins
Hmm. That didn't change things, but it seems like it's ignoring the option. If I exclude the header file from the project, it doesn't seem to be make a difference.
Colin DeClue
@Colin: You're saying you removed the header file and you still get the error on that line of the header file? That seems a bit odd. You might try to do a rebuild all. Or close the file and delete the .pch (pre-compiled header) file.
Mark Wilkins
Colin, you cannot control how the *header* gets compiled. You can only control that for the files that *include* that header. Since the header is evidently C++, you must make sure that no C source files include that header, not even indirectly. And merely removing it from the project won't change anything; if you want to test compilation without that file, you need to make sure that nothing mentions that file in any `#include` statement. Membership in "the project" is irrelevant.
Rob Kennedy
@Rob: Thanks. That answers some things I was confused about, as the header file was throwing some complaints about an extern "C" line. I threw in a check for cplusplus and that fixed that.
Colin DeClue
A: 

If this is a forward declaration for the function in another project try using extern.

DumbCoder
Functions declared at file-level scope are extern implicitly.
Rob Kennedy