Can I place multiple characters within single quotes? For example, is the result of the following statement defined in C:
If this is defined, how does it work and which C standard supports it?Code:'abc';
Can I place multiple characters within single quotes? For example, is the result of the following statement defined in C:
If this is defined, how does it work and which C standard supports it?Code:'abc';
No. Single quotes wrap single characters. That's the syntax.
The only time > 1 character is allowed within single quotes is when the first character is an escape character.
Mainframe assembler programmer by trade. C coder when I can.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Yes, you can do this and for some reason it produces: x = 1094861636. There is not much reason to do so, x is not an address in memory nor is it multiplying the ASCII code for each character, thats what this does:which also does not produce a warning. I can see more of a reason to multiply the ASCII code for each character as this can also be modified to use the other operations aswell, treating characters as numbers. It still is not explicit what the code will actually do reading it, characters are not generally thought of as their ASCII equivalent and other languages would probably crash when given the same code.Code:int x = 'A' * 'B'* 'C' * 'D'
long time no C; //seige
You miss 100% of the people you don't C;
Code:if (language != LANG_C && language != LANG_CPP) drown(language);
This format is quite often used to make multibyte "magic" numbers, such as identifiers of file-formats (for example, BMP files contain 'BM' in the header).
The value is actually ('A' << 24) + ('B' << 16) + ('C' << 8) + 'D', or ('D' << 24) + ('C' << 16) + ('B' << 8) + 'A' depending on the byte-order of the system.
The real benefit of storing it as one int, rather than a character array, is that it can trivially be compared to another item of the same kind with one single instruction, rather than comparing a character array which requires (say) 4 operations, if you don't try to have fun with casting and pointers and such.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.