468,268 Members | 1,681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

(part 34) Han from China answers your C questions

What is this?

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

Nov 20 '08 #1
1 1072
On 20 Nov, 22:36, Borked Pseudo Mailed <nob...@pseudo.borked.net>
wrote:
What is this?
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.
that would all be sorted out at compile time on any reasonable
compiler. Both address-of and casting between pointers are free at run-
time.

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, [its] possible address 0 is in some sense a
pointer (though not in the C sense),
nonsense

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.
by "real" I assume you mean "physical". In what sense is the address/
pointer
referred to in the C program not-real? You seem to be adding
unnecessary
confusion (surprise!)
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
this is correct
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

--
Nick Keighley
Nov 21 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nomen Nescio | last post: by
reply views Thread by Nomen Nescio | last post: by
reply views Thread by Nomen Nescio | last post: by
2 posts views Thread by Chris Dollin | last post: by
2 posts views Thread by Borked Pseudo Mailed | last post: by
1 post views Thread by George Orwell | last post: by
reply views Thread by George Orwell | last post: by
16 posts views Thread by Borked Pseudo Mailed | last post: by
2 posts views Thread by Nomen Nescio | last post: by
1 post views Thread by George Orwell | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.