I am trying to write a tool to translate C-inc-Files into Asm syntax.


Sorry for the out of subject, but i don't read C and have problems
at understanding the Structures Declarations. Someone who speeks
chineese??? Usually the Structures are in the form of:

> typedef struct StructureName1 {
> TYPE Name1;
> TYPE Name2;
> ....;
> } StructureName2,*StructureName3;


Most often, StructureName1 is in the form of "_STRUCTURENAME"

*** What is this '_' for?

*** What are "StructureName2,*StructureName3" for?


Now, sometimes, in these Files, i encount Structures without any title.
Example:

> typedef struct { ; <<<<<<< No Title!!!!
> TYPE Name1;
> TYPE Name2;
> ....;
> } StructureName2,*StructureName3;


If first thaught it was an error, but, as i see this both in ReactOS
includes and in LCC-Win32 includes, it doesn't seem to be an error....

*** Is "StructureName2" the rescue Structure Name in case of missing Title?


Betov.

PS. Please, no link to any C tut, they turn me sea sick :))
Posted on 2001-11-28 06:21:42 by Betov
It's pretty easy. StructureName1 (with the underscore) is needed
if the structure needs to have a pointer to structure of it's own type.
Even when not, it's often included anyway. In pure C, you'd have
to declare a variable as "struct StructureType1 myStructVariable;"
to declare a struct var. However, because of the typedef, you can
use "StructureType2 myStructVariable;" instead. StructureName3
just makes a type for a pointer to the struct, so you can do
"StructureName3 myStrPtr1, myStrPtr2, myStrPtr3;" instead of
"StructureName3 *myStrPtr1, *myStrPtr2, *myStrPtr3;".

Have fun.
Posted on 2001-11-28 06:50:02 by f0dder
Its a typedef and a declaration rolled into one.

It is easier to read (all the info in one place n all), and if there is only one declaration of the type, then it can be done without nameing the structure.

So:
typedef struct blah {
int x;
int y;
} a, *b;

Is a structure called blah, and two variables, one called a which is of type blah, and the other called b which is a pointer to a variable of type blah.


The second case:
typedef struct {
char x;
char y;
} a, *b

This is the same as above, but the structure's name is anonymous, and so unavailable for general use (ie. other declarations etc.).

The underscore before the name is just a naming convention as far as I am aware.

Mirno
Posted on 2001-11-28 06:54:33 by Mirno
Wrong, mirno, they are all type definitions :). However, if the "typedef"
had been missing before "struct", I believe you would have been
right about the stuff following after the closing } of the struct would
have been variables.
Posted on 2001-11-28 07:02:44 by f0dder
StructureName1 is called the structure tag because the struct keyword can be used without a typedef.

Simple but good explanation :

http://www.scit.wlv.ac.uk/~jphb/cbook/html/chap10.structs.basic.html
Posted on 2001-11-28 10:24:40 by jmp $FCE2
Thanks to all....

What is, too, the exact meaning of "tag"?

(I don't even know this word in english...).

Most StructureName1, are in Fact in the form of "tagSTRUCTURENAME"

(Wonderfull language, anyway :))
Posted on 2001-11-28 10:48:43 by Betov