473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Complicated circular type definitions: help!

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
2 2738
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
8
by: Tim Tyler | last post by:
Like C, Python seems to insist I declare functions before calling them - rather than, say, scanning to the end of the current script when it can't immediately find what function I'm referring to. ...
0
by: CHAOS | last post by:
I am trying to set up a schema that will define a structure to hold simple lines of code, where lines consist of function calls with parameters that may or may not be function calls themselves. For...
6
by: Markus Dehmann | last post by:
I have a circular dependency between two classes. The FAQ hint about a forward declaration does not help in my case ( How can I create two classes that both know about each other?) Error:...
16
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
7
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time...
9
by: rammel | last post by:
class1.h ----------- #ifndef CLASS1_H_ #define CLASS1_H_ #include "class2.h" // inclusion class class2; // and forward class class1 { private:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.