Main incompatibility of C code in C++

Started by
4 comments, last by SiCrane 14 years, 2 months ago
Well my question is simple: what are the main things one should watch out for when looking at C code to "port" them to C++ code?
YES I use gamemaker, YES I'm proud of it, NO I don't want to move on yet..WHY? because I don't want to program the interface etc, I just want to focus on simulations with physical formulas and AI pathfinding codes..
Advertisement
What do you mean exactly by "porting" C code to C++? Most modern C++ compilers support the relevant features of C99, meaning that C code will generally compile as C++. Cases where features exist in C99 but not in C++98/03, such as long long, are usually bridged by compiler extensions. Perhaps you're referring to the process of converting a procedural system into an object-oriented one?
Quote:Original post by paul23
Well my question is simple: what are the main things one should watch out for when looking at C code to "port" them to C++ code?


There are very little issues that you might encounter when compiling C as C++ (in terms of compiler errors). For example, if you have some really really old C then you might encounter the old-style function parameters:
func(a, b) // implicit int return type// declaring the parameter typesint a;char b;{    if (b == 'a') return a;    return 42;}

Which is not valid in C++.
Quote:Original post by Windryder
What do you mean exactly by "porting" C code to C++? Most modern C++ compilers support the relevant features of C99, meaning that C code will generally compile as C++. Cases where features exist in C99 but not in C++98/03, such as long long, are usually bridged by compiler extensions. Perhaps you're referring to the process of converting a procedural system into an object-oriented one?


Nah, just to those feature cases as you said.. - It's not that the code won't compile, I just want to know the differences..
YES I use gamemaker, YES I'm proud of it, NO I don't want to move on yet..WHY? because I don't want to program the interface etc, I just want to focus on simulations with physical formulas and AI pathfinding codes..
There are a few C99 features that are not supported by most C++ compilers. For example, most C++ compilers seem to ignore the C99 restrict keyword.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Incompatibilities Between ISO C and ISO C++

This topic is closed to new replies.

Advertisement