472,805 Members | 1,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

(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 1173
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nomen Nescio | last post by:
A new learner's question Flash Gordon wrote: To the OP, please be aware that Flash Gordon has a history of either deliberately misleading and "miss-informing" posters to this newsgroup or...
0
by: Nomen Nescio | last post by:
what is the type for this call? Neo said: Neo, buddy, I've decided to give you a little summary for reference so that you don't have to sift through excess verbiage, cryptic meanderings,...
0
by: Nomen Nescio | last post by:
No format string passed to variable argument list function Adam said: Then Adam laters says: Then Adam later says:
2
by: Chris Dollin | last post by:
Joachim Schmitz wrote: I think that remark is an ill-considered and unhelpful generalisation. -- "We dance, and the worlds melt away." - Curved Air, /Metamorphosis/ ...
2
by: Borked Pseudo Mailed | last post by:
float and integers c.lang.myself@gmail.com said I will be making assumptions here about your system that will infuriate the pedants, but I don't care. Given your X-HTTP-UserAgent string, it...
1
by: George Orwell | last post by:
its urgent.pls help me. mona said: mona said: Hey again, mona. Please check the thread "(part 21) Han from China answers your C questions", in which I gave you a program with
0
by: George Orwell | last post by:
fread breaks file descriptors opened in "w" mode. ... Yes, once you break out of ANSI/ISO C, all things are possible. You have posted an on-topic question to comp.lang.c. See version 2.0 of...
16
by: Borked Pseudo Mailed | last post by:
Error handling in C Nick Keighley said: ... ... To the OP, please be aware that Nick Keighley is a known troll and is deliberately providing you with unsound advice. You asked for error...
2
by: Nomen Nescio | last post by:
What is this? Eric said: That looks like either someone's poor coding or someone's poor pasting for an implementation of offsetof() from stddef.h. The (char *) leads me to think that there's...
1
by: George Orwell | last post by:
File Seeking / Overwriting bytes Martien Verbruggen said: And this is, of course, also not right. fseek() does support SEEK_END on text streams. If you want to know why, please start a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.