I've been reading the others' code to try and learn how to extract wav sample data. In one of the examples I came across, there was an area that confused me. The original author created a structures:
I think I figured it out. Correct me if I'm wrong. XSAMPLE sample = { 0 };
This statement is used to initialize the structure members during the declaration of a structure object. This statement initializes the first member of the structure and is equivalent to the following statement: sample.left = 0;
If it had been written as: XSAMPLE sample = { 0, 0 };
actually, XSAMPLE sample = { 0 }; is equivalent to
1 2
sample.left = 0;
sample.right = 0;
because if you're using this syntax (it's called "aggregate initialization"), then the members of the struct/array that aren't listed explicitly are zero-initialized.
Does this only work when the members are initialized to zero? I ask because I wrote my own little code where instead of zero I put a 5, "CAR sports = {5};":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
typedefstruct{
int doors;
int wheels;
} CAR;
int main ()
{
CAR sports = {5};
cout<< sports.doors <<", " <<sports.wheels <<endl;
sports.doors = 2;
sports.wheels = 4;
cout<< sports.doors <<", " <<sports.wheels <<endl;
system("pause");
return 0;
}
So in other words this is a shortcut to zero out all the members of a structure. For instance, if there were 10 members of a structure you could zero them out by initializing a structure object like this, using my car example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
typedefstruct{
int doors;
int wheels;
int windows;
int mirrors;
int passengers;
} CAR;
int main ()
{
CAR sports = {0};
return 0;
}
So the first member is set to zero and any unlisted members are automatically set to zero, simply because they weren't listed.
Chris
*edit*
Just read vlad from moscow's post, we must have posted at the same time.