By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Complicated circular type definitions: help!

P: n/a
Hi all.

I've got a rather complicated circular type definition, and would
appreciate help getting it sorted out :). Cut-down code below :

8<--------------------------------------------------------

typedef enum { SOLID, NEARESTATOM } surfcoloropt;
typedef float (*FunctionCalc)(MOLECULE *, float, int *, int *, surfcoloropt, unsigned char[4]);
/* Defines a rectangle in 3D space. We store the central point c
* the u and v axes, the number of grid points in the u and v
* directions. Note that the grid
* goes from -nu to +nu, so the total size is (2*nu+1)*(2*nv+1) points.
* Likewise, the extent of the plane in 3D is (c-u-v) to (c+u+v);
*/
struct planestruct {
int nu, nv;
p3 c,u,v;
struct planeoptionstruct *options;
struct planestruct *next;
struct planestruct *prev;
};

typedef struct planestruct PLANE;

typedef struct planeoptionstruct {
float probesize;
float clipmax,clipmin;
FunctionCalc *calc;
} PLANEOPTS;

typedef struct molstr {
//blah
//lots more blah
PLANE *plane
} MOLECULE;

8<--------------------------------------------------------

So, a MOLECULE contains a PLANE, which contains a PLANEOPTS, which
contains a FunctionCalc pointer, which takes a MOLECULE * as one
of its arguments. Is there an easy way of sorting this lot out? I can
do circular references for structs, but this one involving a function
has me confused.

--
Mark Mackey Beam the offer. Two for a
ma**@swallowtail.org cootie-coated Lathian and
http://www.swallowtail.org/ his Willie Terwilliger.

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In message <P+*******@news.chiark.greenend.org.uk>
Mark Mackey <ma***@chiark.greenend.org.uk> wrote:
So, a MOLECULE contains a PLANE, which contains a PLANEOPTS, which
contains a FunctionCalc pointer, which takes a MOLECULE * as one
of its arguments. Is there an easy way of sorting this lot out? I can
do circular references for structs, but this one involving a function
has me confused.


Put all the typedefs and struct tag declarations first, thus:

typedef struct molstr MOLECULE;
typedef struct planestruct PLANE;
typedef struct planeoptionstruct PLANEOPTS;
typedef enum { SOLID, NEARESTATOM } surfcoloropt;
typedef float (*FunctionCalc)(MOLECULE *, float, int *, int *, surfcoloropt, unsigned char[4]);

/* Defines a rectangle in 3D space. We store the central point c
* the u and v axes, the number of grid points in the u and v
* directions. Note that the grid
* goes from -nu to +nu, so the total size is (2*nu+1)*(2*nv+1) points.
* Likewise, the extent of the plane in 3D is (c-u-v) to (c+u+v);
*/
struct planestruct {
int nu, nv;
p3 c,u,v;
struct planeoptionstruct *options;
struct planestruct *next;
struct planestruct *prev;
};

struct planeoptionstruct {
float probesize;
float clipmax,clipmin;
FunctionCalc *calc;
};

struct molstr {
//blah
//lots more blah
PLANE *plane
};

I think you've got too many "*"s on your FunctionCalc though. FunctionCalc
is actually a pointer to a function, and thus planeoptionstruct contains
a pointer to a pointer to a function.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 13 '05 #2

P: n/a
In article <d3****************@tematic.com>,
Kevin Bracey <ke**********@tematic.com> wrote:

Put all the typedefs and struct tag declarations first, thus:
Ah, that makes sense. Thanks!
I think you've got too many "*"s on your FunctionCalc though. FunctionCalc
is actually a pointer to a function, and thus planeoptionstruct contains
a pointer to a pointer to a function.


Yup, that's a bug. I suspect that the compiler would have picked that up,
except for the fact that it wouldn't compile before :).

--
Mark Mackey http://www.swallowtail.org/
code code code code code code code code code code code code code bug code co
de code code code bug code code code code code code code code code code code
code code code code code code code code code code code code code code code c
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.