1

How do I correctly initialize a wchar_t array with wmemset? Should I use '\0' or L'\0' ? Does it matter? does the encoding matter ? (unicode, ISO####)

eg

wchar_t arr[20];
wmemset(arr, '\0', sizeof(arr));
Cœur
  • 37,241
  • 25
  • 195
  • 267
thahgr
  • 718
  • 1
  • 10
  • 27
  • 1
    Hadn't heard of `wmemset` before. Looking at the documentation, the third parameter is the number of characters not bytes so using `sizeof` is wrong. – Mark Ransom May 14 '15 at 15:12

1 Answers1

1

You need to use the L'' form to get a wchar_t type, although any value that fits within a char (such as '\0') will be automatically converted using the usual integer promotions. See character literal or C++ Character Literals.

It's unclear to me what code page the source will be interpreted in. To be safe, it's best to use a L'\u20ac' or L'\U000020ac' form to specify characters outside of the ASCII character set.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • thanks for your answer, to help me clarify, I am talking about specifically wmemset, your anwers refer to that? you say that the trailing zero will be the same with `'\0'` and `L'\0'` ? – thahgr May 15 '15 at 07:55
  • Yes, that's exactly what I'm saying. The parameter to `wmemset` is a `wchar_t`, and if you give a `char` instead it will be promoted so the result is the same. – Mark Ransom May 15 '15 at 12:53