I have been getting back into programming after of being out of it for a few year’s.
I want to seperate my routines into diffrent .cpp files and use my own .h files.
I am using the code from nehe site to setup the window and opengl setup code.
The problem I am having is passing a structure from my routine.
//mystuff.h
struct XYZ_BUFFER
{
float x;
float y;
float z;
int dir_x;
int dir_y;
int dir_z;
};
// end .h
// mystuff.c
#include “mystuff.h” //defines my structure.
XYZ_BUFFER Check_boundary( XYZ_BUFFER bc )
{
// check location of object
// change direction if needed
// code not shown but works when in main program.
return( bc )
}
What is the proper way to access from another my main.c program.
It works when I have it all in one file…
MikeC
July 13, 2000, 8:19am
2
What error message are you getting?
EricK
July 13, 2000, 8:47am
3
Just guessing, but I noticed that you passed bc by value. You might want to pass by reference:
XYZ_BUFFER Check_boundary( XYZ_BUFFER & bc )
The error message is during linking…
LNK 2001 unresolved external symbol
here is how my routine is defined in my main.c program.
XYZ_BUFFER xyz_object[64];
XYZ_BUFFER Check_boundary(XYZ_BUFFER);
what is the correct way to call a routine
and pass a varible structure from another .c file.
phlake
July 13, 2000, 12:44pm
5
this is a dumb question, but you’re including “mystuff.h” in main.c, right?
and mystuff.h should have a prototype for the function you’re calling in mystuff.c
[This message has been edited by phlake (edited 07-13-2000).]
Originally posted by phlake:
[b]this is a dumb question, but you’re including “mystuff.h” in main.c, right?
and mystuff.h should have a prototype for the function you’re calling in mystuff.c
[This message has been edited by phlake (edited 07-13-2000).][/b]
Yea, I have the mystuff.h in both mystuff.c and main.c
If anyone is interested I can zip the code and e-mail it to you…
I know it has to be something very simple!
DFrey
July 13, 2000, 1:48pm
8
Is one file a .cpp and another .c? That can cause linker errors like that, if the call type isn’t explicity indicated.
system
July 14, 2000, 6:46am
9
In your .h try
typedef struct
{
…
} XYZ_BUFFER;
Alternatively, in your .cpp
change references to XYZ_BUFFER to
‘struct XYZ_BUFFER’.
system
July 14, 2000, 7:43am
10
Originally posted by Troy:
[b]In your .h try
typedef struct
{
…
} XYZ_BUFFER;
Alternatively, in your .cpp
change references to XYZ_BUFFER to
‘struct XYZ_BUFFER’.[/b]
Ooops… you can see my C background bias…
I notice that this isn’t necessary for C++
So, the second part of phlake’s ‘dumb’
question still applies, does your
.h file include a function prototype?
XYZ_BUFFER Check_Boundary(XYZ_BUFFER bc);
Here is some more code.
//mysuff.h
typedef struct // this structure definded for the location of each pyramid
{
float x;
float y;
float z;
int dir_x;
int dir_y;
int dir_z;
}XYZ_BUFFER;
// end mystuff.h
//mystuff.cpp
#include “mystuff.h”
XYZ_BUFFER check_boundary( XYZ_BUFFER xyz_ptr )
{
if ((xyz_ptr.x > 2.0f) | (xyz_ptr.x < -2.0f))
{
xyz_ptr.dir_x = xyz_ptr.dir_x * -1;
};
if ((xyz_ptr.y > 2.0f) | (xyz_ptr.y < -2.0f))
{
xyz_ptr.dir_y = xyz_ptr.dir_y * -1;
};
if ((xyz_ptr.z > 6.0f) | (xyz_ptr.z < -6.0f))
{
xyz_ptr.dir_z = xyz_ptr.dir_z * -1;
};
return( xyz_ptr );
}
// end mystuff.cpp
// part of the code of pyramid.cpp (main)
XYZ_BUFFER xyz_buffer[64]; // this is the location varible for each pyramid
XYZ_BUFFER check_boundary( XYZ_BUFFER ); // define my routine
check_boundary(xyz_buffer[63]); // how I call my routine.
//end pyramide.cpp
what you think???
I have got the program to work now, thanks for the input.
Eric