Click to See Complete Forum and Search --> : HELP! TYPEDEF


ashes jingles
April 16th, 1999, 06:59 AM
What do you make of this [1] thing in the code below. I have no clue. Your help will be greatly appreciated.

typedef struct
{
int8 font;
uchar path;
} txtspec;
typedef txtspec tspec[1];
typedef tspec *tspecptr;
typedef tspecptr *tspechandle;




Thanks
-ashes

Dave Lorde
April 16th, 1999, 07:55 AM
> typedef txtspec tspec[1];

This makes tspec[1] a type synonym for txtspec. The syntax '[1]' is that of an array with one element, e.g:

char foo[1]; // declares foo as an array of 1 char

The typedef looks a bit unusual, but it's just another way of referring to the txtspec struct.

Dave

M Grundberg
April 16th, 1999, 08:07 AM
To clarify a bit, if you declare a variable of type tspec:

tspec pfoo;

pfoo will be a single-element array of txtspec. The following code would have the same result:

txtspec foo;
txtspec* pfoo = foo;


/Michael Grundberg
M.Sc. Computer Science
Visionova IT-System, Sweden
michael@itsystem.se