aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/stringlit.c
blob: 155f8ebb081d99bf5352b2d71a0d0a372512d2af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <wchar.h>
#include <uchar.h>

/* Without escapes nor universal character names */

unsigned char s1[] = "aé猫🍌";
unsigned char s2[] = u8"aé猫🍌";
char16_t s3[] = u"aé猫🍌";
char32_t s4[] = U"aé猫🍌";
wchar_t s5[] = L"aé猫🍌";

/* With universal character names */

unsigned char t1[] = "a\u00e9\u732B\U0001F34C";
unsigned char t2[] = u8"a\u00e9\u732B\U0001F34C";
char16_t t3[] = u"a\u00e9\u732B\U0001F34C";
char32_t t4[] = U"a\u00e9\u732B\U0001F34C";
wchar_t t5[] = L"a\u00e9\u732B\U0001F34C";

/* With numerical escapes */

unsigned char e1[] = "a\xe9\350";
unsigned char e2[] = u8"a\xe9\350";
char16_t e3[] = u"a\xe9\350\x732B";
char32_t e4[] = U"a\xe9\350\x732B\x0001F34C";
wchar_t e5[] = L"a\xe9\350\x732B\x0001F34C";

#define PRINT(x) \
  printf("%s: size %u, contents", #x, (int) sizeof(x)); \
  for (int i = 0; x[i] != 0; i++) printf(" %x", x[i]); \
  printf("\n")

int main()
{
  PRINT(s1); PRINT(s2); PRINT(s3); PRINT(s4); PRINT(s5);
  PRINT(t1); PRINT(t2); PRINT(t3); PRINT(t4); PRINT(t5);
  PRINT(e1); PRINT(e2); PRINT(e3); PRINT(e4); PRINT(e5);
  return 0;
}