1

I’m trying to cast the value 247 to a char in C++ (Visual Studio). I’m getting a Debug Assertion Failed error, saying unsigned(c+1) should be less than or equal to 256. I don’t understand where this is coming from since the value 247 falls in that range.

liz
  • 11
  • 3

1 Answers1

-2

unsigned char range is 0 .. 255 char range is -128 to 127

ChrisBD
  • 9,104
  • 3
  • 22
  • 35
  • 1
    That's not right. `signed char` range is -128 to 127; `char` range is implementation-defined. (Strictly speaking, even that's not right: the implementation is free to use larger ranges. But nobody does.) – TonyK Jul 05 '21 at 17:23
  • We're looking at Microsoft C++ compiler in Visual Studio here, in which case it uses a single octet (byte) for a char and it is signed by default unless the compiler switch `/J` is used. – ChrisBD Jul 06 '21 at 06:31
  • Then you should make that clear in your answer. – TonyK Jul 06 '21 at 08:18
  • Why - when its stated the question? – ChrisBD Jul 06 '21 at 08:19