02-01-2018 01:02 PM - edited 02-01-2018 01:22 PM
Hi,
I am helping in troubleshoot a software issue (developed in LabWindows/CVI 2015), and one thing I have noticing and find weird is that the software code initializes the array by assigning an empty bracket or empty string. For example
double Array[10] = {0};
char Buffer[1024] = "";
myMap NameMap = {0, "", "", ""} //myStructure contains - int, char[1024], char [1024], char [1024]
I wonder would that method is truly initialize the array? or if that could cause memory leak in the software as my assumption is that "" and {} are consider as a constant in the memory, and assigning array to that constant would forces the pointer to change. And, as the constant does not have sufficient memory allocated, an update to the array would cause memory leak?!
Thanks.
Peggy
02-01-2018 03:15 PM
double y [ 10 ] = { 0 }; is a valid and standard way to initialize all elements with zero. You can check this e.g. with 'Variable View" (Shift + F7)
02-06-2018 03:28 AM
Hi,
partial explicit initializations like double Array[10] = {0} are working in two steps:
You can read more here: http://en.cppreference.com/w/c/language/struct_initialization or obviously in the C standard.