Develop porting from c to cpp
-
The extensions of the source code files must be changed from .c to .cpp and from .h to .hpp so that the files are recognized by the C++ compiler
-
Add makefile rules to compile and link c++ sources. Reflect changed file extensions.
-
The C header files are named differently in C++. E.G.:
"math.h"
-><cmath>
-
C++ does not offically support the
restrict
type qualifier. But most compiler offer the alternative__restrict__
-
C++ depreceated support of the Storage-class specifier
register
-
In C, a string such as
“Hello world”
is of typechar *
in C++ it is correctly of typeconst char *
. Such a string can of course only be passed to functions that specify the input parameter asconst char *
. -
A swicht-case block forms a single scope. This means that variables that are declared in one case are also available in the subsequent cases. However, if jumping directly to one of the subsequent cases, these variables are uninitialized. This is not allowed in C++
-
External headers of C libraries must be linked according to the C convention, not the C++ convention. E.G:
extern "C" { #include "cseife.h" }
-
A struct can be partially initialized. The order of the initialized elements in C is arbitrary, as the initialization has no side effects. In C++, the elements must be initialized in the order in which they appear in the struct, because each initialization potentially calls a constructor, which can then rely on the preceding elements being initialized.
-
In C++, the min and max functions exist as templates and do not have to be defined as macros
-
C does a implicite type cast from
void *
to any kind of pointer type. C++ requires explicite type casts
Merge request reports
Activity
assigned to @holger.obermaier
added 1 commit
- 5f49266f - Rename source code files from .c to .cpp and from .h to .hpp
added 1 commit
- 61797cf5 - The C header files are named differently in C++
added 1 commit
- 9c65b538 - C++ does not offically support the restrict type qualifier. But most compiler...
added 1 commit
- 5bfb684a - C++ depreceated support of the Storage-class specifier register
added 1 commit
- f4371a7e - The extensions of the source code files must be changed from .c to .cpp
added 1 commit
- b2e5acc8 - The extensions of the source code files must be changed from .h to .hpp
added 1 commit
- ecc439f9 - External headers of C libraries must be linked according to the C convention
added 1 commit
- 31f2afd9 - A struct can be partially initialized. The order of the initialized elements...
added 1 commit
- 1cfccaf5 - Add makefile rules to compile and link c++ sources
added 1 commit
- a0a91a79 - In C++, the min and max functions exist as templates and do not have to be defined as macros
added 1 commit
- f2c289f4 - C does a implicite type cast from void * to any kind of pointer type. C++...
added 1 commit
- 6c147b41 - In C, a string such as “Hello world” is of type char * in C++ it is correctly...