J
Joakim Hove
Hello,
to promote data-hiding I have come across the following technique,
which I quite like:
Header file xxx.h:
------------------
typedef struct xxx_type xxx_type;
xxx_type * xxx_alloc(int);
-------------------------
Source file xxx.c:
-----------------
struct xxx_type {
double *data;
int size;
};
xxx_type * xxx_alloc(int size) {
xxx_type *xxx;
xxx = malloc(sizeof *xxx);
xxx->size = size;
....
return xxx;
}
-------------------------
What I wonder is what really happens at the struct xxx_type {};
statement in the source file. To me it seems like a struct is defined,
but it is not used for anything - i.e. not for a typedef nor to
instantiate an object.
So - I guess I my question is really: "What does the compiler do -
when it meets a
struct foo {
....
....
};
statement.
Best Regards
Joakim Hove
--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (73 5)9 34 27 / Stabburveien 18
Fax: ................. / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04
to promote data-hiding I have come across the following technique,
which I quite like:
Header file xxx.h:
------------------
typedef struct xxx_type xxx_type;
xxx_type * xxx_alloc(int);
-------------------------
Source file xxx.c:
-----------------
struct xxx_type {
double *data;
int size;
};
xxx_type * xxx_alloc(int size) {
xxx_type *xxx;
xxx = malloc(sizeof *xxx);
xxx->size = size;
....
return xxx;
}
-------------------------
What I wonder is what really happens at the struct xxx_type {};
statement in the source file. To me it seems like a struct is defined,
but it is not used for anything - i.e. not for a typedef nor to
instantiate an object.
So - I guess I my question is really: "What does the compiler do -
when it meets a
struct foo {
....
....
};
statement.
Best Regards
Joakim Hove
--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (73 5)9 34 27 / Stabburveien 18
Fax: ................. / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04