Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to port existing C++ code to C++11

We are working on a module that is developed in C++, but given the new C++11, I am thinking about migrating to that.

How to proceed? Are both the same or is there some compiler dependency?

My software currently supports Windows and Linux. I am using Microsoft Visual Studio as well as GCC to build it.

Overall, what changes are needed if any?

like image 604
Amit Kumar Avatar asked Jun 02 '13 07:06

Amit Kumar


People also ask

How do you use C 11 in VS code?

To build using C11 or C17, put your source code in a . c file, or set the code to compile as C. You can set this property for your project on the Configuration Properties > C/C++ > Advanced page.

What is porting in C?

Portability refers to how easily- if at all- code can move from one system architecture to another. We know that Linux is a portable because it has already been ported to various implementations. To view which implementations Linux has ported to, type in the following command. vim /usr/src/kernels/2.6.43.8-1. fc15.

How do I enable C ++ 17 in GCC?

C++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.


1 Answers

Old C++ will work with your C++11 Compiler

  • Reviewing how you use iterators (maybe you can move to range-for)
  • Review if you use function pointer (maybe you can use lamdaes)
  • Review Class Initiators (maybe you can write initialization list)
  • Review your pointer use (maybe you can switch to SmartPtr)
  • Review your use to NULL with pointer maybe you can move to nullptr
like image 70
Baget Avatar answered Oct 22 '22 11:10

Baget