Page 1 of 1

Structs in C

Posted: Tue Jun 29, 2004 9:16 am
by n00b
If I want to fill a descriptiontable, e.g. the IDT, I found it easy to use a struct... but I cant get my structs working in C!
if I do something like this:
struct mystruct {
int yadayada;
};
and then..
mystruct i;
i.yadayada = 5;
I get the error message:
idt.c:6: error: request for member `yadayada' in something not a structure or

how come?

Re:Structs in C

Posted: Tue Jun 29, 2004 9:51 am
by Pype.Clicker
your declaration does not alias "mystruct" to the structure. The correct code would be

Code: Select all

   struct mystruct { ...  } ;

    struct mystruct i;
     i.yadayada=5;

Re:Structs in C

Posted: Tue Jun 29, 2004 9:55 am
by Pype.Clicker
oh, and btw, beware of compiler alignment of fields ...

Code: Select all

struct IdtRegister {
   word limit;
   dword base;
}
usually has a size of 8, not of 6 as asm programmers could expect.

Code: Select all

struct ldtRegister {
    word padding;
    word limit;
    dword base;
} IDTR;

lidt(&(IDTR.limit));
is to be preferred to the "expectable" code.

Re:Structs in C

Posted: Tue Jun 29, 2004 11:00 am
by minotaurcomputing
your declaration does not alias "mystruct" to the structure.
Further, if you in fact wanted to alias mystruct to refer to the structure, then you would have to use typedef.
-m