D
DaveLessnau
I'm trying to learn C on my own and, apparently, my brain went on
vacation somewhere. I just can't figure out how to parse the following
function call:
"void fillDeck( Card * const wDeck, const char * wFace[], const char *
wSuit[])"
Card is aliased before that call with:
"typedef struct card Card"
the card structure is define before that with:
"struct card {
const char *face;
const char *suit;
};"
and the paramter passed via wDeck is defined in main as:
"Card deck[ 52 ]" /* an array of 52 card structures */
Looking around the web, this seems to be a fairly standard example
program. In that call to fillDeck, the first parameter seems to parse
as sending a pointer to an instance of type Card (in this case, the
address to the first Card in the 52 element array of Cards) but making
sure the receiving function can't modify it (with the "const"
modifier). I've got to be reading that wrong, because the sole purpose
of fillDeck is to modify wDeck by filling it using a for loop:
"for ( i = 0; i <= 51; i++ ) {
wDeck[ i ].face = wFace[i % 13 ];
...."
Can anyone shed some light on how I'm misreading that function call?
Probably related to it: can anyone tell me why the dereferencing
operator * is separated from its variable? IOW, why
"void fillDeck( Card * const wDeck,..."
instead of
"void fillDeck( Card *const wDeck,..." (*const instead of * const)
or, heck,
"void fillDeck( Card const *wDeck,..." (const *wDeck instead of * const
wDeck)?
vacation somewhere. I just can't figure out how to parse the following
function call:
"void fillDeck( Card * const wDeck, const char * wFace[], const char *
wSuit[])"
Card is aliased before that call with:
"typedef struct card Card"
the card structure is define before that with:
"struct card {
const char *face;
const char *suit;
};"
and the paramter passed via wDeck is defined in main as:
"Card deck[ 52 ]" /* an array of 52 card structures */
Looking around the web, this seems to be a fairly standard example
program. In that call to fillDeck, the first parameter seems to parse
as sending a pointer to an instance of type Card (in this case, the
address to the first Card in the 52 element array of Cards) but making
sure the receiving function can't modify it (with the "const"
modifier). I've got to be reading that wrong, because the sole purpose
of fillDeck is to modify wDeck by filling it using a for loop:
"for ( i = 0; i <= 51; i++ ) {
wDeck[ i ].face = wFace[i % 13 ];
...."
Can anyone shed some light on how I'm misreading that function call?
Probably related to it: can anyone tell me why the dereferencing
operator * is separated from its variable? IOW, why
"void fillDeck( Card * const wDeck,..."
instead of
"void fillDeck( Card *const wDeck,..." (*const instead of * const)
or, heck,
"void fillDeck( Card const *wDeck,..." (const *wDeck instead of * const
wDeck)?