This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Forward declaration is not possible
- From: Peter Haase <p dot haase at tu-harburg dot de>
- To: gsl-discuss at sources dot redhat dot com
- Date: Thu, 12 Dec 2002 14:28:04 +0100
- Subject: Forward declaration is not possible
Hi,
using GSL to implement some random generators, I would like to make a forward
declaration for 'gsl_rng' and 'gsl_rng_type' (Otherwise, I have to include
the GSL header files in my header file and clients using my random generators
must have these GSL header files available ). Unfortunatley a forward
declaration is not possible since both 'gsl_rng' and 'gsl_rng_type' are not
names of a struct but are defined by typedef as new types:
(In gsl_rng.h:)
typedef struct
{
char* name;
....
} gsl_rng;
The reason for this is obvious to avoid the keyword struct when using the name
gsl_rng in c-code.
My suggestion is to use 'gsl_rng' as a name of the struct and as typename for
that struct:
(Suggested new code in gsl_rng.h)
typedef struct gsl_rng // ( ansi c ? if not use 'tag_gsl_rng' instead)
{
char* name;
....
} gsl_rng;
With that code it is possible to use the gsl as used before and it is possible
to use a forward declaration and hence to avoid unneccessary #includes of the
GSL header files. I'm not pretty shure if it's strict ANSI C code when using
the same token 'gsl_rng' for both the name and the typename (my GCC 3.2
Compiler does not complain about that). If that is not allowed in ANSI C, the
token 'tag_gls_rng' could be used for the name of struct (see comment above).
Even that is much more convenient than dealing without a forward declaration.
Peter