VLA Initialization

The following line of code that creates an array of variable length on the stack:

char name[cpfs_params(cfdata->cpfs)->namemax + 1] = {'\0'};

Creates the following compiler diagnostics:

src / mount.cpfs / cpfsfuse.c: 179: error: variable object cannot be initialized

src / mount.cpfs / cpfsfuse.c: 179: warning: redundant items in an array initializer

src / mount.cpfs / cpfsfuse.c: 179: warning: (near initialization for the name)

What options are available for initializing VLA? I am forced to use a string, for example:

memset(name, 0, sizeof(name));

Instead

+3
source share
1 answer

, VLA ( memset(), , , ).

C (§6.7.8):

  • , .
+4

Source: https://habr.com/ru/post/1779303/


All Articles