Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

basic c++ question on character data types --- I know i can declare a char letter like this. char letter = 'A'; or char letter = 65; And I know you can declare a wide char like this wchar_t letter = L'Z'; My question is this... is wchar_t letter = 'Z' equivilent to wchar_t letter = L'Z'

OpenStudy (anonymous):

forgot the ; but you get the idea

OpenStudy (e.mccormick):

The L tells it you are using a string litteral.

OpenStudy (anonymous):

it is not a string :P string is " " not ' ' double vs single. the L tells i am using a wide char

OpenStudy (anonymous):

L means a 16 bit char

OpenStudy (e.mccormick):

It comes from the C standard.

OpenStudy (e.mccormick):

Well, a wide string literal, to be more clear.

OpenStudy (anonymous):

I am more confused now.

OpenStudy (anonymous):

string means it is a character array terminated by a \0 so L'W' vs L"W" is not the same cuzz one is terminated by \0

OpenStudy (e.mccormick):

Ah, found another reference in the same book. "An L prefix distinguishes wide character constants. (See §2.2.1.2.)" So it is both. And they never say why L for Wide... unless it was a reference to long....

OpenStudy (anonymous):

Long was another thing i was thinking about

OpenStudy (e.mccormick):

And 2.2.1.2 is no help at all for the why of this. 2.2.1.2 Multibyte characters The “byte = character” orientation of C works well for text in Western alphabets, where the size of the character set is under 256. The fit is rather uncomfortable for languages such as Japanese and Chinese, where the repertoire of ideograms numbers in the thousands or tens of thousands. Internally, such character sets can be represented as numeric codes, and it is merely necessary to choose the appropriate integral type to hold any such character. Externally, whether in the files manipulated by a program, or in the text of the source files themselves, a conversion between these large codes and the various byte media is necessary. The support in C of large character sets is based on these principles: • Multibyte encodings of large character sets are necessary in I/O operations, in source text comments, and in source text string and character literals. • No existing multibyte encoding is mandated in preference to any other; no widespread existing encoding should be precluded. • The null character (\0) may not be used as part of a multibyte encoding, except for the one-byte null character itself. This allows existing functions which manipulate strings transparently to work with multibyte sequences. • Shift encodings (which interpret byte sequences in part on the basis of some state information) must start out in a known (default) shift state under certain circumstances, such as the start of string literals. • The minimum number of absolutely necessary library functions is introduced. (See §4.10.7.)

OpenStudy (e.mccormick):

And you will love this... the end of that is: "The minimum number of absolutely necessary library functions is introduced. (See §4.10.7.)" Right? So here is 4.10.7: 4.10.7 Multibyte character functions See §2.2.1.2 for an overall discussion of multibyte character representations and wide characters.

OpenStudy (e.mccormick):

This is an official documen from when they wrote the ANSI C Standard.... so if it is not here, the reaosning is lost. LOL. Looks like they chose it as some sort of prefix marker for the compiler and nobody made note of why.

OpenStudy (e.mccormick):

Here: Turned it into a PDF. It was a TEX file.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!