Mika avatar

Porting code written for old compiler to new compiler

mtl1979

Published: 31 Oct 2020 › Updated: 31 Oct 2020

Porting code written for old compiler to new compiler

Recently I installed newer version of Ubuntu Linux (20.04) and noticed it doesn't have GCC 6 anymore... I know my code compiled with GCC 7 already, but I was curious how much it would take to make it compile with GCC 8 or newer, and more recent versions of Clang.

GCC 7 to GCC 8

  • Most important change is that for simple variable types, copying using memcpy() is now discouraged. Direct assignment should be used instead.

GCC 8 to GCC 9

  • When returning a class that has same type as return type of a function, std::move() should not be explicitly used.

GCC 9 to GCC 10

  • cstdint and stdexcept headers need to be explicitly included when using standard integer types or throwing run-time exceptions

GCC to Clang

  • Clang use different options to disable warnings
    • For example -Wlogical-op and -Wno-maybe-uninitialized are not supported
  • Clang requires explicit copy constructor if there is copy assignment operator
  • Clang requires explicit move constructor if there is move assignment operator
  • Clang requires explicit virtual destructor, if class has virtual methods
  • Clang requires "override" keyword for virtual methods that override existing method in derived class

Leave Porting code written for old compiler to new compiler to:

Written by

Freelance journalist, software designer

Read more #programming posts


Best Posts From Mika

We have not curated any of mtl1979's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Mika