Eric said:
A more detailed block of code is:...
bool result;
bool GetByte( char *theAddr, int theCount, char *theDest);
char Dest[ SOME_SIZE ];
result =
GetByte( ( char * ) &( ( struct aStruct * ) 0 )->Addr,
1, ( char * ) ( &Dest ) );
My question is... does the struct aStruct live at address 0, or does
address 0 contain a pointer to wherever aStruct actually lives? Seems
to me like the "&" ahead of ( ( struct aStruct * ) 0 )->Addr would
indicate the latter...
it's an embedded system, uses an ARM7-based controller.That ( char * ) ( &Dest ) is like two cups of redundancy. I'd hate to
think that this embedded system is a pacemaker or something.
As for "does address 0 contain a pointer to wherever aStruct actually
lives?", no and yes. No, the code appears to be referring to a structure
that begins at address 0, or at least is temporarily treating the data
there as a structure. Yes, it's possible address 0 is in some sense a
pointer (though not in the C sense), since the ARM MMU supports virtual
memory, and the actual address that winds up on the address bus needn't
refer to a real address of 0.
I believe your confusion is a result of binding the "&" before the "->".
&( ( struct aStruct * ) 0 )->Addr is broken down as follows:
1. 0
2. (struct aStruct *) 0
--3. ( ( struct aStruct * ) 0 )->Addr
4. &( ( struct aStruct * ) 0 )->Addr
I believe you're making the mistake of breaking it down as follows:
1. 0
2. (struct aStruct *) 0
--3. &( ( struct aStruct * ) 0 )
4. &( ( struct aStruct * ) 0 )->Addr
Yours,
Han from China