Fred wrote:
>
Can anyone explain what the point of this is?
For example, code like:
typedef struct {
int alloc;
char *data;
} my_struct;
typedef my_struct my_type_t[1];
What's the advantage of making the my_type_t type an array of 1
my_struct? Why not either just make it a plain typedef for the struct,
or else make it a typedef for a pointer to the struct?
It's an attempt to do things like "pass by reference" rather than
"pass by value" when referring to my_type_t.
(Crossing fingers and hoping I don't mess this up.)
Consider:
void func(void)
{
my_struct foo;
my_type_t bar;
func2(foo,bar);
}
Here, "foo" will be passed by value, but bar will be passed by
reference (sort of) because it's an array.
It has an advantage over a pointer-to-struct, because:
typedef my_struct *my_type_t2;
...
my_type_t2 foobar;
will not allocate storage for the struct.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>