Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Pointer for ROM variable in a RAM variable?

Name: Anonymous 2012-11-20 17:54

I'm doing a project using the Microchip C18 compiler.
I have a struct called a block that points to other blocks (north east south west)
These blocks will make me a map.
I then have a pointer that I use to evaluate everything.
Just using RAM it looks like:

struct block{
        struct block *north, *east, *south, *west;
};
struct block map[5] = {     // just a simple line.
        { NULL, &map[1], NULL, NULL },
        { NULL, &map[2], NULL, &map[0]},
        { NULL, &map[3], NULL, &map[2]},
        { NULL, &map[4], NULL, &map[3]},
        { NULL, NULL, NULL, &map[4]}
};
struct block* position = &map[0];

This lets me do stuff like:

void goWest()
{
        if(position -> west != NULL) position = position -> west;
}


I ran out of RAM however, so here is my attempt at using rom:

struct block{
        rom struct block *north, *east, *south, *west;
};
rom struct block map[5] =
{ // just a simple line.
        { NULL, &map[1], NULL, NULL }
        .....

If done some debugging and can tell the above part works, but trying to make the position pointer is giving me grief.
so I guess my question is:

How do I hold the rom variable addresses in a pointer which I can edit the values of?

When i try: struct block *position = &map[0];
I get "Warning [2066] type qualifier mismatch in assignment"

I realize that a rom variable and ram variable are two different things,
but I have no idea what to do.

Name: Anonymous 2012-11-20 18:04

*position = &map[0];
Look at what you're doing. You're assigning a pointer to a struct. You either want position = &map[0]; or *position = map[0];, but I don't know which one.

Name: Anonymous 2012-11-20 18:18

>>2
I just tried that
>position = &map[0];

but now i get the error:
Error [1213] initializer list expected

Name: Anonymous 2012-11-20 18:20

>>2
What? That's just false.

Name: Anonymous 2012-11-20 19:04

I don't know C18's extensions, but I bet struct block *position must be declared to be a pointer-to-rom.

Name: Anonymous 2012-11-20 19:34

found my answer.

At each pointer level, you can have a const qualifier or lack thereof, and likewise for the base non-pointer object. So, a single-level pointer can have 4 different variants:

int *x;  // Non-constant pointer to non-constant data
int *const x;  // Constant pointer to non-constant data
const int *x;  // Non-constant pointer to constant data
int const *x;  // Same as above
const int *const x;  // Constant pointer to constant data
int const *const x;  // Same as above

Name: Anonymous 2012-11-21 0:25

>>6
Mnemonic: const always modifies the type to the left. If there's nothing on the left, swap the two leftmost keywords. I always write int const instead of const int to keep things consistent.

Name: Anonymous 2012-11-21 4:50

>>7
heh... constistent.....

Name: Anonymous 2012-11-21 5:00

>>1
ROM
variable

pick one

Don't change these.
Name: Email:
Entire Thread Thread List