Multi-character constant warnings
According to the standard (§6.4.4.4/10)
The value of an integer character constant containing more than one
character (e.g., 'ab'), [...] is implementation-defined.
long x = '\xde\xad\xbe\xef'; // yes, single quotes
This is valid ISO 9899:2011 C. It compiles without warning under gcc
with -Wall
, and a “multi-character character constant” warning with -pedantic
.
From Wikipedia:
Multi-character constants (e.g. 'xy') are valid, although rarely
useful — they let one store several characters in an integer (e.g. 4
ASCII characters can fit in a 32-bit integer, 8 in a 64-bit one).
Since the order in which the characters are packed into one int is not
specified, portable use of multi-character constants is difficult.
For portability sake, don't use multi-character constants with integral types.
C++: Multi-character character constant warning when reading from a file into char array
/n
is constant consisting of two chars, '/'
and 'n'
and you are not quoting it as a string, using "
, but as a char, using '
, hence warning.
Maybe you wanted to use backslash instead of slash, i.e. '\n'
?
Related Topics
C++11 Return Value Optimization or Move
How to Use a Binary Literal in C or C++
How to Add Additional Libraries to Visual Studio Project
Floating Point Division VS Floating Point Multiplication
C++11 Does Not Deduce Type When Std::Function or Lambda Functions Are Involved
Static Linking VS Dynamic Linking
How to Make a Http Request With C++
Initialization Order of Class Data Members
Difference of Keywords 'Typename' and 'Class' in Templates
C++ Lambda With Captures as a Function Pointer
Why Does Cout Print Char Arrays Differently from Other Arrays
Can Main Function Call Itself in C++