I’m maintaining and extending the functionality of a diagnostic test suite, and this fragment of code comes up multiple times and I’m not sure what it does:
int ret = 0, i, *reg;
int size = sizeof(Regs)/sizof(Reg);
for(i = 0; i<size; i++) {
reg= (uint*)Regs[i].Number;
*reg=0;
}
return ret;
Where i is looping variable, and reg is a pointer to a 32-bit int (Number being the address to that 32-bit int). This particular test clears the registers, but is it meant to change ret?
EDIT: I guess my question was a bit ambiguous, I am wondering specifically what the fragment:
int ret = 0, i, *regs;
Does, or why it is valid.
int ret = 0, i, *reg;defines three variables: an
intcalledret, anintcallediand anint*calledreg. Onlyretis initialized (to0).The reason is that the grammar for a declaration (slightly simplified) is:
Here the declaration-specifiers are just
int, then we have an init-declarator list consisting of three init-declarators. One of them has an initializer and the other two don’t. The declarator*regdefines a “pointer-to-whatever-type-the-declaration-specifiers-say”. See 6.7 “Declarations” in the standard for the gory details (and the bits I left out of the grammar above).