vendredi 24 avril 2020

What differences in behaviour can there be for a single program between C and C++?

First of all, I know the main differences between C and C++. But before I've thought that a certain subset of syntax for both languages is identical. However in passing discussion I've heard it mentioned that even if the program uses syntax limited enough to be legal and well-defined both in C and C++, it still can have different behaviour. I've met quite a few compiler-specific extensions that add C-like behaviour to C++, sometimes not quite as they actually work in C. But I can't think of differences for parts that are standard-defined.

To make this question better defined, here's what I'm interested in:

  • Languages compared are C11 and C++11
  • A single program that is well-defined both in C11 and C++11 standards. No undefined behaviours, no compiler-specific syntax. Any parts that are implementation-defined should be considered equivalent if possible.
  • Standard-mandated differences in behaviour of the same program depending on which language is applied.

Note that I realise it's much easier to find such a program for two specific compilers. What I'm interested is differences in standards specifically.

Aucun commentaire:

Enregistrer un commentaire