Re: How to read/write an 'address' from a memory location......



On Oct 20, 12:04 am, Hans-Bernhard Bröker <HBBroe...@xxxxxxxxxxx>
wrote:
aeroboro...@xxxxxxxxxxxxxx wrote:
I am trying to read an address from a memory location and then write
into that memory location.

Which "that" --- the one you read the address from, or the one the
address specifies?

unsigned long * mem_pointer = 0x93700020;
unsigned long mem_value = *mem_pointer;

The question is - How do i use the value at <i> mem_value </i> as an
address?

An address kept in a variable is called a pointer, in C programs. So
mem_value should be of a pointer type, rather than an integer.
Consequentially, mem_pointer should be a pointer-to-pointer-to-something
type, e.g.

some_type **mem_pointer = ...;
some_type *mem_value = *mem_pointer;
some_type the_actual_thing = *mem_value;

Basically, I want to do something like.
*(unsigned char *)mem_value = 10.

And what's keeping you from doing exactly that?

But this all hides a probably more important question: why do you think
you should be doing this?

My problem is: I have two processors exchanging data over a shared
section of memory. Now before processor 1 can write the data for
processor 2 (in the shared memory), processor 1 needs to tell
processor 2 where exactly it will be writing. Thats where i was coming
from - processor 1 basically needs to write an "address" into a
predefined location for processor 2 and that "address" will hold the
actual data for processor 2.

Thanks a lot for all your clarifications. I should try some of them
now!

Warm regards,
Rintu

.



Relevant Pages

  • Re: ((struct name *)0)->b ?
    ... I'm referencing the NULL pointer and not the memory location at zero ... Instead of defining the "null pointer constant" the way C ...
    (comp.lang.c)
  • Re: pointer int/char ...
    ... > declaration/definition of pointer varibles. ... Line 7 the expression "linux" evaluates to the memory address that the ... This is telling the compiler to printf the integer at memory location 4. ... darrell at cs dot toronto dot edu ...
    (comp.lang.c)
  • Re: union with packed struct
    ... :than one memory location for any one given address then you'll have an ... then the compiler might choose to lay A out in memory as ... are addressing modes that take a base address and an index and access ... Converting a pointer to and back again ...
    (comp.lang.c)
  • Re: Another question related to pointers.
    ... > access a memory location until that memory has been allocated either by ... A pointer SHOULD NOT BE USED to access ... If C can't do this how are you supposed to write a malloc function in C ...
    (comp.lang.c)
  • Re: Another question related to pointers.
    ... > access a memory location until that memory has been allocated either by ... A pointer SHOULD NOT BE USED to access ... If C can't do this how are you supposed to write a malloc function in C ...
    (comp.lang.c)