codebase:add_cpp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
codebase:add_cpp [2017/05/25 03:10] – vodur | codebase:add_cpp [2019/07/13 06:16] (current) – vodur | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | TL;DR: | ||
+ | |||
+ | * Need to fix C headers to not have C++ keywords. | ||
+ | * Need to add code to verify/ | ||
+ | * Otherwise, the general mechanics for C/C++ interop apply (need to use extern " | ||
+ | |||
+ | Notes and details below. | ||
+ | |||
Trying to just compile existing C code as C++ will likely cause many errors and may have potential functional differences (not likely, but possible). | Trying to just compile existing C code as C++ will likely cause many errors and may have potential functional differences (not likely, but possible). | ||
Line 9: | Line 17: | ||
[[http:// | [[http:// | ||
- | C/C++ interop is well supported. We can compile C files as C into object files and C as C++ into object files and link them without issue. | + | C/C++ interop is well supported. We can compile C files as C into object files and C++ as C++ into object files and link them without issue. |
To access C functions from C++, C++ code will need to include the C headers (wrapping in extern " | To access C functions from C++, C++ code will need to include the C headers (wrapping in extern " | ||
- | To access C++ functions from C, C++ needs to define | + | To access C++ functions from C, C++ needs to declare |
The extern " | The extern " | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
So we have to make sure that any header file used by both C and C++ is compatible with both. For existing C files the big sticking points will be use of C++ keywords. Renaming can clear most of this up, but bool typedefs is another story. | So we have to make sure that any header file used by both C and C++ is compatible with both. For existing C files the big sticking points will be use of C++ keywords. Renaming can clear most of this up, but bool typedefs is another story. | ||
Line 22: | Line 34: | ||
<code C++> | <code C++> | ||
- | |||
#ifndef BOOLTYPE_H | #ifndef BOOLTYPE_H | ||
#define BOOLTYPE_H | #define BOOLTYPE_H | ||
Line 80: | Line 91: | ||
</ | </ | ||
- | [[https:// | + | Basically, C++ is not guaranteed to be implemented as a char but it generally is, and almost certainly is and always will be when using GCC. We can even add the static asserts as above just for some peace of mind. |
- | [[https://stackoverflow.com/questions/8284167/nested-structures-in-c-and-c|https://stackoverflow.com/questions/8284167/nested-structures-in-c-and-c]] | + | [[https://bitbucket.org/aarchon/mud_src/commits/ |
codebase/add_cpp.1495681829.txt.gz · Last modified: 2017/05/25 03:10 by vodur