Hi,
Just wondering if anyone knows the command to wrap a section of code in C++ so that it is C instead, but the whole file stays as C++?
Thanks in advance
Printable View
Hi,
Just wondering if anyone knows the command to wrap a section of code in C++ so that it is C instead, but the whole file stays as C++?
Thanks in advance
What??? I'm not sure what you are trying to do but you can call C functions from within a C++ source file. If you make a C source code file of your own and then try to call them from within a C++ source file, then your prototypes would need an extern "C" declaration. If you #include a C header when you are compiling a C++ source file, you can see in the headers that they typically automatically do this for you with some type of declaration along the following:
If you are compiling a C file then when the headers are read, these are ignored. However when you are compiling a C++ source file, then the headers automatically have these added for you. Not sure if this is what you are asking...Code:#ifdef __cplusplus
extern "C" {
#endif
// misc. declarations in here
#ifdef __cplusplus
}
#endif
[edit]The above may be implementation dependant, I don't know. This was for the headers installed under MSVC. Somebody know if this standardized in any way or even required in other compilers?[/edit]
Read this FAQ section 32
> but the whole file stays as C++?
Use what hk_mp5kpdw showed you.
You can call 'C' functions from C++, but in any single module of code, it will be compiled as C or C++.
> Somebody know if this standardized in any way or even required in other compilers?
I think the approach you have is standard amongst all ANSI compliant C++ compilers.