Defining initial values in the variable declaration happens at a different place than using memset.
For the former case the zeros are defined in some form in the binary as zero init memory (or non-zero depending on what you initialize to), and you hope that the loader honors that, has ABSOLUTELY nothing to do with C language standards. The latter, using memset depends on the C library which you would also works. I have more faith in the library.
I do a lot of embedded code where you learn to avoid the bad habit of initializing variables as part of the variable declaration and instead do it within the code.
For standard operating systems, Linux, Windows, etc the init during variable declaration is fine, you will get an imperceptible performance increase, but if you are running an operating system you are on a platform that is fast enough to not see that difference.
Depending on the binary type the former case of the init during declaration can make the binary larger. This is extremely easy to test for. Compile your binary as above, then change the array size from [16] to [16000] then compile again. Then compile without the = {0x00} and compare the three binary sizes.
For most systems that most programmers will ever see, there is no functional difference. I recommend the memset as a habit. Despite what standards say many if not most C compilers (of which most programmers will never see in their careers) wont like that init because the number of elements doesnt match the size. Most compilers do not conform to the standards even if they claim to. Instead develop good habits that avoid shortcuts or pretty much anything that should work for standard X but is different from the prior standard M. (Avoid any gee whiz compiler or standards based tricks).
answered 2009-05-10T04:55:55.523