GP32 Include File For C++


pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
46
Location
New Zealand
Website
www.projectitis.com
Hi all

could somebody please explain to me the include file 'cpp_prototypes.h' in Mr.Mirkos SDK? It is included at the bottom of 'gp32.h' and basically looks like this:

Code:
#ifndef GP32_CPLUSPLUS_H
#define GP32_CPLUSPLUS_H

#include <fileio.h>
#include <sprite.h>
......
#include all other headers in the library here

#ifdef __cplusplus
extern "C" {
#endif
        #ifndef size_t
        #define size_t int
        #endif

        // gp_cpuspeed.c
        int  gp_getPCLK();
        int  gp_getHCLK();
        void gp_setCpuspeed(int freq);
        void gp_Reset();

        // gp_grafik.c
        void  gp_drawPixel8  (int x, int y, u8 c, u8 *framebuffer);
        void  gp_drawPixel16 (int x, int y, u16 c, u16 *framebuffer);

        ......
        PROTOTYPE EVERY FUNCTION IN THE ABOVE INCLUDE FILES
        ......

        
        // gp_cpuspeed.c
        int  gp_getPCLK();
        GPFILE *smc_fopen(const char *path, const char *mode);
        ......
        void    smc_rewind(GPFILE *stream);
        int     smc_filesize(GPFILE *stream);

#ifdef __cplusplus
}
#endif

#endif

Note: I have obviously removed some for the example above and replaced them with ......

I know that it makes available all the Mirko library functions, but what I would like to know is, why are we redefining the prototypes if __cplusplus is defined? If cplusplus is defined, does the compiler ignore the #include files at the top of the file or something???
 
Very handy, thanks blah :p

The reason I ask is because I have added (so far) at least 30 functions to the SDK, and I have been dilligently adding them to cpp_prototypes.h also. I would really like to know why. If I leave them out by mistake, it still works for me you see (though I don't use c++).
 
What I do is not include my functions (I haven't made many) in the SDK, but rather as separate libraries because I figure if I really want a function to be part of the SDK, I'll send it to Mr. Mirko. :) But whatever....
 
The only thing regarding __cplusplus that I could see in that code is basically just putting

extern "C" {
}

over that huge chunk of code if __cplusplus is defined.
 
It's not like that for me. o_O
GP32.h has a bunch of #defines for variables, and then it #includes cpp_prototypes.h, which has what you posted above.

I'm only actually seeing the prototypes once. Maybe I'm just not understanding what you're asking...
 
pea posted on May 2 2005 at 07:17 PM said:
oh true, yes I agree.

But why include the prototypes again if the headers are already at the top?

They are not included in the other header files.
 
Last edited by a moderator:
So they aren't! What a true brain freeze I had.

Only the structs and typedefs are defined in the headers, not the function prototypes.

How odd.
 
Back
Top