Why Is This Program Erroneously Rejected by Three C++ Compilers

Why is this program erroneously rejected by three C++ compilers?

In the standard, §2.1/1 specifies:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary.

Your compiler doesn't support that format (aka cannot map it to the basic source character set), so it cannot move into further processing stages, hence the error. It is entirely possible that your compiler support a mapping from image to basic source character set, but is not required to.

Since this mapping is implementation-defined, you'll need to look at your implementations documentation to see the file formats it supports. Typically, every major compiler vendor supports (canonically defined) text files: any file produced by a text editor, typically a series of characters.


Note that the C++ standard is based off the C standard (§1.1/2), and the C(99) standard says, in §1.2:

This International Standard does not specify

— the mechanism by which C programs are transformed for use by a data-processing
system;

— the mechanism by which C programs are invoked for use by a data-processing
system;

— the mechanism by which input data are transformed for use by a C program;

So, again, the treatment of source files is something you need to find in your compilers documentation.

Why is this program erroneously rejected by three C++ compilers?

In the standard, §2.1/1 specifies:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary.

Your compiler doesn't support that format (aka cannot map it to the basic source character set), so it cannot move into further processing stages, hence the error. It is entirely possible that your compiler support a mapping from image to basic source character set, but is not required to.

Since this mapping is implementation-defined, you'll need to look at your implementations documentation to see the file formats it supports. Typically, every major compiler vendor supports (canonically defined) text files: any file produced by a text editor, typically a series of characters.


Note that the C++ standard is based off the C standard (§1.1/2), and the C(99) standard says, in §1.2:

This International Standard does not specify

— the mechanism by which C programs are transformed for use by a data-processing
system;

— the mechanism by which C programs are invoked for use by a data-processing
system;

— the mechanism by which input data are transformed for use by a C program;

So, again, the treatment of source files is something you need to find in your compilers documentation.

Program being compiled differently in 3 major C++ compilers. Which one is right?

GCC is correct, at least according to C++11 lookup rules. 3.4.3.1 [class.qual]/2 specifies that, if the nested name specifier is the same as the class name, it refers to the constructor not the injected class name. It gives examples:

B::A ba;           // object of type A
A::A a; // error, A::A is not a type name
struct A::A a2; // object of type A

It looks like MSVC misinterprets it as function-style cast expression creating a temporary C with y as a constructor parameter; and Clang misinterprets it as a declaration of a variable called y of type C.

Why are there duplicate C/C++ compilers (e.g g++, gcc)?

The executable can determine the name it was called with by inspecting the first (or zeroth) command line argument passed to it. By convention it is the name of the executable and is passed by whatever program is invoking the compiler (typically e.g. a shell).

Although it is the same executable, it can then take different actions based on whether or not that value is gcc or g++.

Also, the files you are seeing are unlikely to be duplicate files. They are most likely just (soft or hard) links to the same file.


For the part that clang/clang++ and gcc/g++ seem to be the same, although they are completely different compilers, that is an Apple quirk. They link gcc and g++ to clang and clang++ for some reason, but in reality both refer to Apple clang, which is also different from upstream clang. It often causes confusion (at least for me).



Related Topics



Leave a reply



Submit