4

I am looking at some code from one of our customers and found this function parameter I've never seen before:

some_function('ESFc');

In the debugger I set the value to

char c = 'ESFc';

and it equals 99

He also is using 'ESSc', 'ESCm' and 'ESBd' which eval to 99, 109 and 100

What is this? Is it some kind of escape code?

Mat
  • 202,337
  • 40
  • 393
  • 406
Mossen
  • 1,275
  • 2
  • 12
  • 15

1 Answers1

7

It's a multi-character literal, but its value is not 99. The type of 'ESFc' is actually an int, and when you store it in a char it loses precision. See this question:

What do single quotes do in C++ when used on multiple characters?

Community
  • 1
  • 1
K-ballo
  • 80,396
  • 20
  • 159
  • 169
  • I believe C does not support multi-character literals while C++ does. – Mark Ransom Oct 13 '11 at 21:18
  • @Mark Ransom: I wouldn't know about that, but I'd assume C supports them as well. Yet his question is tagged C++ and even says C++ in the title. – K-ballo Oct 13 '11 at 21:18
  • The tags are both C++ and C, and sometimes StackOverflow decides to add a tag to the title. – Mark Ransom Oct 13 '11 at 21:20
  • @Mark Ransom: StackOverflow does that? Still C does support multi-literal characters as well. – K-ballo Oct 13 '11 at 21:23
  • @MarkRansom: "sometimes StackOverflow decides to add a tag to the title" is news to me. Is this discussed somewhere on meta? – Ben Voigt Oct 13 '11 at 21:51
  • Sorry, it appears I was confused - C and C++ both support multi-character literals. There is a difference between C and C++ with single-character literals, but that's irrelevant to the question. – Mark Ransom Oct 13 '11 at 21:52
  • @BenVoigt, I think my brain is just breaking down this afternoon. I should delete every comment on this thread. – Mark Ransom Oct 13 '11 at 21:54