Thanks for all the replies. I don't think I was very clear in my post
so let me illustrate with an example. The code I'm developing, written
in C++, is a dll that is used by another application to create geometry
objects (solid models). As such, there are many operations involved,
and to keep it organized I would like to put each operation in its own
function. So the general structure looks something like this:
******************************************
{headers}
{function prototypes}
{structure definitions}
// MAIN FUNCTION FOR CREATING OBJECT
long CreatePrimative(struct FunctionLib* functionLib, void*
callbackData, double* paramValues)
{
// CREATE 2D OUTLINE OF OBJECT
long profile = CreatProfile(functionLib, callbackData, paramValues);
// EXTRUDE PROFILE INTO 3D
long object = CreateObject(functionLib, callbackData, paramValues,
profile);
return object;
}
// USER FUNCTIONS
long CreateProfile(struct FunctionLib* functionLib, void* callbackData,
double* paramValues)
{
double r=paramValue[0];
double theta=paramValue[1];
double pi = 3.1415926;
double x1 = r*cos(theta + pi/2);
double y1 = r*sin(theta + pi/2);
.
{compute "profile", return as a pointer}
.
return profile;
}
long CreateObject(struct FunctionLib* functionLib, void* callbackData,
double* paramValues, profile)
{
double r=paramValue[0];
double theta=paramValue[1];
double pi = 3.1415926;
double x1 = r*cos(theta + pi/2);
double y1 = r*sin(theta + pi/2);
double z1 = sqrt(x1*x1 + y1*y1);
.
{compute "object", return as a pointer}
.
return object;
}
*************************************************************************
Now in this example, the variable "z1" is only used in the second
function (CreateObject). But to calculate it, I need to compute x1 and
y1, quantities that were also calculated in the first function
(CreateProfile). This involves repeating some variable assignments as
well (r, theta, pi). So to avoid all this repetition, I would like to
somehow make x1 and y1, when computed in the first function, available
for use in second. My first thought was to make x1 and y1 global, but
I'm not sure how to do that in C++. Can it be done in this context?
Perhaps a better way is to put everything that needs to pass out into a
structure. Any opinions?
My actual code is much more complicated, with more functions and many
more variable definitions and calculations. So being able to share
information between these is pretty im****tant.
Thanks for any advice with this. -Pat


|