This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pointer to array in a structure?

hello,

i have a simple little structure like this

unsigned char index;

struct tag {
unsigned char a[20];
unsigned char b[20];
unsigned char c
};

then i declare a pointer like this

struct tag TAG_PTR;

it seems that TAG_PTR->c; is valid and generates no errors

however TAG_PTR->a[index]; generated BAD OPPERAND TYPE error

and TAG_PTR->a[10];(or any other constant value)
and TAG_PTR->a; generate no errors.

obviously using the index variable is the problem, but im not sure how to work around it. Any help would be greatly appreciated.

Parents
  • then i declare a pointer like this

    struct tag TAG_PTR;
    

    Like that, you're not declaring a pointer at all.

    it seems that TAG_PTR->c; is valid

    It's not.

    obviously using the index variable is the problem

    No, it's not. The problem is that you didn't actually declare TAG_PTR as a pointer.

Reply
  • then i declare a pointer like this

    struct tag TAG_PTR;
    

    Like that, you're not declaring a pointer at all.

    it seems that TAG_PTR->c; is valid

    It's not.

    obviously using the index variable is the problem

    No, it's not. The problem is that you didn't actually declare TAG_PTR as a pointer.

Children