Search code examples
ctranslationdeclarationstring-concatenationstring-literals

Why can an array encompass elements of strings?


I don't comprehend why double quotes are included in the following array; isn't this of string type?

const uint8_t u8x8_font_8x13_1x2_n[436] U8X8_FONT_SECTION("u8x8_font_8x13_1x2_n") = 
  " :\1\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0@P\340\340P@\0\0\0\1\0\0\1\0\0\0\0\0\300\0\0\0\0\0\1\1\7"
  "\1\1\0\0\0\0\0\0\0\0\0\0\0 \30\30\10\0\0\0\0\0\0\0\0\0\0\0\0\1\1\1"
  "\1\1\0\0\0\0\0\0\0\0\0\0\0\0\20\70\20\0\0\0\0\0\0\0\200@\60\0\30\4\2\1"
  "\0\0\0\0\0\300 \20\20 \300\0\0\7\10\20\20\10\7\0\0@ \360\0\0\0\0\0\20\20\37"
  "\20\20\0\0\0`\20\20\20\20\340\0\0\30\24\22\22\21\20\0\0\20\20\20\220P\60\0\0\10\20\21"
  "\21\21\16\0\0\0\200@ \360\0\0\0\7\4\4\4\37\4\0\0\360\20\220\220\220\20\0\0\11\21\20"
  "\20\20\17\0\0\300 \20\20\20\0\0\0\17\22\21\21\21\16\0\0\20\20\20\220P\60\0\0\0\30\6"
  "\1\0\0\0\0\340\20\20\20\20\340\0\0\16\21\21\21\21\16\0\0\340\20\20\20\220\340\0\0\0\21\21"
  "\21\10\7\0\0\0\200\300\200\0\0\0\0\0\20\71\20\0\0";

The following example represents my commonly used declaration format for arrays.

int arr[10]={1,2,3,4,5,6,7,8,9,10};

Solution

  • From the C Standard (5.1.1.2 Translation phases)

    1 The precedence among the syntax rules of translation is specified by the following phases.

    //...

    1. Adjacent string literal tokens are concatenated.

    So for example this declaration

    char s[] = "Hello World!";
    

    is equivalent to

    char s[] = "Hello " 
               "World!";
    

    Such splitting of a big string literal into several adjacent string literals makes code more readable.