1.26 -fshort-wchar, -fno-short-wchar

-fshort-wchar sets the size of wchar_t to 2 bytes. -fno-short-wchar sets the size of wchar_t to 4 bytes.

The -fshort-wchar option can improve memory usage, but might reduce performance because narrow memory accesses can be less efficient than full register-width accesses.

Note:

All linked objects must use the same wchar_t size, including libraries. It is not possible to link an object file compiled with -fshort-wchar, with another object file that is compiled without -fshort-wchar.

Default

The default is -fno-short-wchar.

Example

This example shows the size of the wchar_t type:

#include <stdio.h>
#include <wchar.h>

int main(void)
{
  printf("size of wchar_t is %zd\n", sizeof (wchar_t));
  return 0;
}

When compiled without the -fshort-wchar option, the size of wchar_t is 4 bytes:

armclang --target=aarch64-arm-none-eabi -mcpu=cortex-a53 wchar_test.c
                
size of wchar_t is 4

When compiled with the -fshort-wchar option, the size of wchar_t is 2 bytes:

armclang -fshort-wchar --target=aarch64-arm-none-eabi -mcpu=cortex-a53 wchar_test.c
                
size of wchar_t is 2
Non-ConfidentialPDF file icon PDF versionDUI0774J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.