Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: custom routines and MSC++

  1. #1
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    custom routines and MSC++

    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....

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    562

    Re: custom routines and MSC++

    What error message are you getting?

  3. #3
    Intern Newbie
    Join Date
    Jul 2000
    Location
    Millis, MA USA
    Posts
    37

    Re: custom routines and MSC++

    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 )

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: custom routines and MSC++

    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.

  5. #5

    Re: custom routines and MSC++

    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).]

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: custom routines and MSC++

    Originally posted by phlake:
    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).]
    Yea, I have the mystuff.h in both mystuff.c and main.c

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: custom routines and MSC++

    If anyone is interested I can zip the code and e-mail it to you...

    I know it has to be something very simple!

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: custom routines and MSC++

    Is one file a .cpp and another .c? That can cause linker errors like that, if the call type isn't explicity indicated.

  9. #9
    Guest

    Re: custom routines and MSC++

    In your .h try
    typedef struct
    {
    ...
    } XYZ_BUFFER;

    Alternatively, in your .cpp
    change references to XYZ_BUFFER to
    'struct XYZ_BUFFER'.

  10. #10
    Guest

    Re: custom routines and MSC++

    Originally posted by Troy:
    In your .h try
    typedef struct
    {
    ...
    } XYZ_BUFFER;

    Alternatively, in your .cpp
    change references to XYZ_BUFFER to
    'struct XYZ_BUFFER'.
    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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •