Structs in C

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
n00b

Structs in C

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Structs in C

Post 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;
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Structs in C

Post 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.
minotaurcomputing

Re:Structs in C

Post 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
Post Reply