I am back into c/Linux. The question might look stupid, but relevant after working in c# etc.
I have some structures inside structures and the hierarchy level is more than 5. In such a case, I am doing an initialisation of every structure at the beginning explicitly. I know c does not have a new() method that will do it for you. Now I wish to know if there is any tool/widget that might create this code of initiating the structures for me. Its a tedious job and can speed up my work.
If all you want to do is to initialize everything to zeroes, you can initialize your
structwith{0}, which is always going to initialize everything to0.From the C standard, 6.7.8 (emphasis mine):
In plain terms,
{0}is the correct initializer for any aggregate type. So,struct foo bar = { 0 };initializes the first element ofbarto0, and the rest are initialized recursively to their respective zero values.If you want to initialize the members to non-zero values, you may want to write a function. Note that the “zero” value is correct for each data type. This may not be all-bits-zero for pointers and/or floating-point values.
gccwith-Walloption by default warns if you don’t have “enough” braces, but the warning is harmless if you know what you’re doing. You can disable the with-Wno-missing-braces