Can someone please tell me how to point a data structure that I have created to a particular memory address?
TIA.
Can someone please tell me how to point a data structure that I have created to a particular memory address?
TIA.
It sounds like you need a good Pointers in C - Tutorial - Cprogramming.com
Quzah.
Hope is the first step on the road to disappointment.
Sounds like you need to read it again. If you understand pointers, then you understand how to point anywhere you feel like. If you don't understand pointers, then you need to go and actually read it this time.
Quzah.
Hope is the first step on the road to disappointment.
If that tutorial doesn't explain it well enough, Google will find dozens, if not hundreds of other ones to read. Do you have a textbook or class notes you can review? This one is a little longer and more in depth, but good: Eternally Confuzzled - All About Pointers.
I am still not finding out how you can set the address to point a structure too. I see plently of examples online for pointing an integer type variable to address but not a structure type variable.
Is this possible:
I am trying to get ptr_Results to point to address 0x1F700000. Please let me know if this correct.Code:typedef struct { Summary_Type SummaryBlock; Log_Type FaultLog[10]; } Result_Type; Result_Type *ptr_Results = (* Result_Type) 0x1F700000;
Assuming your OS actually lets you do that, yes.
Quzah.
Hope is the first step on the road to disappointment.
Yeah, that's correct. A pointer contains an address. The type of that pointer (int, struct, etc) just tells the compiler what kind of data it should expect there, so the int pointer examples translate very easily to your struct pointer examples. Note that assigning pointers to literal addresses is rarely a good idea unless you're in some embedded system or such, where, e.g., you have direct access to memory mapped IO.
This didn't compile... It didn't work for the struct data type.
I have similar examples in my code where it worked for a int.
int *mem = (int*) START_ADDR;
but it didn't work for the struct. Any more hints please?
Oh, because your type cast is backwards. Try (Result_Type *) 0x17F00000.
Thank you!! That solved it..
One more question please, can you please tell me how I would set 1 bit in an int type? like the MSB (31st bit)?
Hope is the first step on the road to disappointment.
I understand the concepts of bitwise operators but I don't know the syntax.
I already zeroed out my variable by initializing it to zero as a whole
int x = 0; for example, and I want to know how to set the 31st bit to a particular value. Can someone please help me?