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
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]
Last edited by hk_mp5kpdw; 08-13-2004 at 05:44 AM.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.