Mixing C with C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

Can an MFC C++ (VS 2005) project have .c files that contain C style
functions? Can these C functions use the classes created in the project?

RML
 
RML said:
Hi all,

Can an MFC C++ (VS 2005) project have .c files that contain C style
functions?

What exactly are C-style functions? You can write free functions (i.e.
functions not bound to a class) in C++ just as in C. In any case, yes, you
can have C files in a C++ project.
Can these C functions use the classes created in the
project?

C functions cannot access classes since classes aren't part of the C
language. Free functions written in C++ can access classes, of course.

-cd
 
When I add a .c file to my project, it failed the compile "wants me to
include stdafx.h. When I do this it fails the compile with this error.

Error 1 fatal error C1853: 'WinSystemsEPXC3 (x86)\Debug/AutoABTester.pch'
precompiled header file is from a previous version of the compiler, or the
precompiled header is C++ and you are using it from C (or vice
versa) d:\dev\Wabtec\WinCE-AutoAB-Tester\AutoABTester\AutoABTester\TestC.c 1

How do I get this c file to compile?
 
RML said:
When I add a .c file to my project, it failed the compile "wants me
to
include stdafx.h. When I do this it fails the compile with this
error.

Error 1 fatal error C1853: 'WinSystemsEPXC3
(x86)\Debug/AutoABTester.pch'
precompiled header file is from a previous version of the compiler,
or the
precompiled header is C++ and you are using it from C (or vice
versa)
d:\dev\Wabtec\WinCE-AutoAB-Tester\AutoABTester\AutoABTester\TestC.c
1

How do I get this c file to compile?

By removing the "Use precompiled headers" option for that particular
file.

Note that the project properties allows individual settings for each
file.


Bo Persson
 
RML said:
When I add a .c file to my project, it failed the compile "wants me to
include stdafx.h. When I do this it fails the compile with this error.

Error 1 fatal error C1853: 'WinSystemsEPXC3 (x86)\Debug/AutoABTester.pch'
precompiled header file is from a previous version of the compiler, or the
precompiled header is C++ and you are using it from C (or vice
versa) d:\dev\Wabtec\WinCE-AutoAB-Tester\AutoABTester\AutoABTester\TestC.c 1

How do I get this c file to compile?
[snip}

Remove "Using pre-compiled headers" from the Properties of this file.
Or, try compiling at C++ by changing the Properties to "Compile as C++."

David Wilkinson
 
Back
Top