Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a valid C++11 program with the expression 'C++11'?

Tags:

c++

c++11

The name of the programming language C++ derives from the parent language C and the ++ operator (it should arguably be ++C) and, hence, the expression C++ may naturally occur in C++ programs. I was wondering whether you can write a valid C++ program using the 2011 standard (without extensions) and containing the expression C++11 not within quotes and after pre-processing (note: edited the requirement, see also answer).

Obviously, if you could write a C++ program prior to the 2011 standard with the expressions C++98 or C++03, then the answer is a trivial yes. But I don't think that was possible (though I don't really know). So, can it be done with the new armory of C++11?

like image 589
Walter Avatar asked Apr 04 '13 16:04

Walter


People also ask

Does C ++ 11 include C11?

No, C++11 does not support ALL the features of C11. It does not even support all the features of C99. Variable-length arrays, for example, were introduced in C99, but C++ does not yet support them.

What is required in each C++ program?

Every C++ program has one and ONLY one function called main() Token: smallest individual program unit. Token: divided into special symbols, word symbols, and identifiers.


1 Answers

NO if we require the characters C++11 to be outside any literal, after preprocessing -- because at translation phase 7 the three tokens will be identifier, ++ and integer-literal

The first two tokens are a postfix-expression, the later is a primary.

There is no reduction in the grammar that can contain these two nonterminals in sequence, so any program containing C++11 will fail syntax analysis.

However, if you do not consider character literals to be strings, then the answer is YES as you can contain it in a wide character literal:

int main()
{
    wchar_t x = L'C++11';
}

which does not use the preprocessor or a string literal, and the construct is required to be supported by the standard:

The value of a wide-character literal containing multiple c-chars is implementation-defined.

like image 193
7 revs, 2 users 77% Avatar answered Nov 16 '22 01:11

7 revs, 2 users 77%