c++cteensy

VS Intellisense shows escaped characters for some (not all) byte constants


In Visual Studio C++ I have defined a series of channelID constants with decimal values from 0 to 15. I have made them of type uint8_t for reasons having to do with the way they are used in the embedded context in which this code runs.

When hovering over one of these constants, I would like intellisense to show me the numeric value of the constant. Instead, it shows me the character representation. For some non-printing values it shows an escaped character representing some ASCII value, and for others it shows an escaped octal value for that character.

const uint8_t channelID_Observations = 1;     // '\001'
const uint8_t channelID_Events = 2;           // '\002'
const uint8_t channelID_Wav = 3;              // '\003'
const uint8_t channelID_FFT = 4;              // '\004'
const uint8_t channelID_Details = 5;          // '\005'
const uint8_t channelID_DebugData = 6;        // '\006'
const uint8_t channelID_Plethysmography = 7;  // '\a'
const uint8_t channelID_Oximetry = 8;         // 'b'
const uint8_t channelID_Position = 9;         // ' ' ** this is displayed as a space between single quotes
const uint8_t channelID_Excursion = 10;       // '\n'
const uint8_t channelID_Motion = 11;          // '\v'
const uint8_t channelID_Env = 12;             // '\f'
const uint8_t channelID_Cmd = 13;             // '\r'
const uint8_t channelID_AudioSnore = 14;      // '\016'
const uint8_t channelID_AccelSnore = 15;      // '\017'

Some of the escaped codes are easily recognized and the hex or decimal equivalents easily remembered (\n == newline == 0x0A) but others are more obscure. For example decimal 7 is shown as '\a', which in some systems represents the ASCII BEL character.

Some of the representations are mystifying to me -- for example decimal 9 would be an ASCII tab, which today often appears as '\t', but intellisense shows it as a space character.

  1. Why is an 8-bit unsigned integer always treated as a character, no matter how I try to define it as a numeric value?

  2. Why are only some, but not all of these characters shown as escaped symbols for their ASCII equivalents, while others get their octal representation?

  3. What is the origin of the obscure symbols used? For example, '\a' for decimal 7 matches the ISO-defined Control0 set, which has a unicode representation -- but then '\t' should be shown for decimal 9. Wikipedia C0 control codes

  4. Is there any way to make intellisense hover tips show me the numeric value of such constants rather than a character representation? Decoration? VS settings? Typedefs? #defines?


Solution

  • After more than a year, I've decided to document what I found when I pursued this further. The correct answer was implied in djgandy's answer, which cited Wikipedia, but I want to make it explicit.

    With the exception of one value (0x09), Intellisense does appear to treat these values consistently, and that treatment is rooted in an authoritative source: my constants are unsigned 8-bit constants, thus they are "character-constants" per the C11 language standard (section 6.4.4).

    For character constants that do not map to a displayable character, Section 6.4.4.4 defines their syntax as

    6.4.4.4 Character constants

    Syntax

    . . .

    ::simple-escape-sequence: one of

    \'

    \"

    \?

    \\

    \a

    \b

    \f

    \n

    \r

    \t

    \v

    ::octal-escape-sequence:

    \ octal-digit

    \ octal-digit octal-digit

    \ octal-digit octal-digit octal-digit

    "Escape Sequences" are further defined in the C language definition section 5.2.2:

    §5.2.2 Character display semantics

    2) Alphabetic escape sequences representing nongraphic characters in the execution character set are intended to produce actions on display devices as follows:

    \a (alert) Produces an audible or visible alert without changing the active position.

    \b (backspace) Moves the active position to the previous position on the current line. If the active position is at the initial position of a line, the behavior of the display device is unspecified.

    \f ( form feed) Moves the active position to the initial position at the start of the next logical page.

    \n (new line) Moves the active position to the initial position of the next line.

    \r (carriage return) Moves the active position to the initial position of the current line.

    \t (horizontal tab) Moves the active position to the next horizontal tabulation position on the current line. If the active position is at or past the last defined horizontal tabulation position, the behavior of the display device is unspecified.

    \v (vertical tab) Moves the active position to the initial position of the next vertical tabulation position. If the active position is at or past the last defined vertical tabulation position, the behavior of the display device is unspecified.

    3) Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object. The external representations in a text file need not be identical to the internal representations, and are outside the scope of this International Standard.

    Thus the only place where Intellisense falls down is in the handling of 0x09, which should be displayed as

    '\t'

    but actually is displayed as

    ''

    So what's that all about? I suspect Intellisense considers a tab to be a printable character, but suppresses the tab action in its formatting. This seems to me inconsistent with the C and C++ standards and is also inconsistent with its treatment of other escape characters, but perhaps there's some justification for it that "escapes" me :)