Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22048

Initializing a dynamically-sized Variable-Length Array (VLA) to 0 [duplicate]

$
0
0

The following line of code, which creates a variable-length array on the stack:

char name[length] = {'\0'};

Generates the following compiler diagnostics:

error: variable-sized object may not be initializedwarning: excess elements in array initializerwarning: (near initialization for ‘name’)

What options are available to me for initializing VLAs? Am I forced to use a line such as:

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

Instead?


Viewing all articles
Browse latest Browse all 22048

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>