
how to modify a pointer to an array one sizeof(int)
Quote:
>My question is under the following situation:
> struct {
> float a;
> float b;
> .....
> float n;
> } *ay;
>Inside the memory, there stored a series of number of type:
> add value
> -----------------------------
> 0000 int
> 0002 float
> 0006 float
> 0010 float
> ... ...
> XXXX float
>The array named ay is somehow pointed to 0000, i.e. ay = 0000;
ay isn't an array, it is a pointer. Speciifc memory addresses such as thing
are fairly meaningless in standard C, there is no standard mechanism
to set a pointer to such an address (since how addresses are formed and
interpreted is inherently platform-specific). You need to check your
compiler documentation as to if and how it supports it. A common approach
is to cast an integer value to a pointer type but don't bet on it or
how the integer values are interpreted.
Quote:
>How can I modify the pointer to the array ay to 0002, i.e. let
>ay = 0002, so that I can use ay[0].a to access the first float number at
>0002, and so on.
Another issue is alignment. On many platforms 2 as an address isn't
correctly aligned to access a float. Such an access might cause the
program to crash.
--
-----------------------------------------
-----------------------------------------