2

If the following is a one byte array:

char arr[] = "\xFF";

If we do the following:

char arr[] = "\xFFmyrandomstringappendedafterbyte";

printing it would result in this:

byteValueGoesHEREmyrandomstringappendedafterbyte

However, if I try to do the following:

char arr[] = "\xFF98";

It will result in a warning:

warning: hex escape sequence out of range

It treats 98 as part of the hexcode. However, I would it to be treated as a string (as is myrandomstringappendedafterbyte).

I would like to have this as output byteValueGoesHERE98.

How can this be achieved without a whitespace? How can I denote that 98 should be treated as a string?

3
  • 1
    @KenWhite Apologies, I have updated my question. It was too vague before. Commented Nov 30, 2019 at 1:54
  • We need to see your actual code. Commented Nov 30, 2019 at 2:01
  • 2
    arr[] is not a one byte array. It is a two byte array. 2nd byte is '\0'. Commented Nov 30, 2019 at 2:08

1 Answer 1

3

When string literals have only whitespace (or nothing) between them, the preprocessor combines them into a single string literal, but this does not "merge" escape sequences. So you can just write your desired string using two strings:

char arr[] = "\xFF" "98";

This is four bytes including the terminating '\0'.

Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively, note that octal and unicode escapes have a finite length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.