Skip to content
Snippets Groups Projects

Develop porting from c to cpp

Open Holger Obermaier requested to merge develop_porting_from_c_to_cpp into develop
  • 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 type char * in C++ it is correctly of type const char *. Such a string can of course only be passed to functions that specify the input parameter as const 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

Edited by Holger Obermaier

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading