As far as I know, the static inline functions work as described in readme.bgi only for GNU C. In all other compilers, if a static inline function is not inlined [inline is a request only, the compiler may ignore it], the compiler stores a static copy of that function in each module that references it, or, in a case of a s####y compiler, in each module that sees it, thus greatly enlarging the size of executables and libraries generated. The patch below: - uses static inline for GNU C only, or - uses inline if the compiler supports it, or - just declares and defines regular functions. In the last case, the functions are declared always, but defined only once: when the header is included from bccgrx.c, which defines __BCCGRX_C. The _BGI_IPROTO_ define is to distinguish between inline functions being inlined or being declared and defined. Compiled and tested with BCC. GRX library size dropped from 740 to 620KB with the patch applied. However test/bgi/bgilink may fail if a non-GNU C compiled providing inline functions but not addresses for them is used. In theory any compiler should switch to non-inline if the address of an inline function is requested, but who knows...
diff -Nru3 grx245-1/include/libbcc.h grx/include/libbcc.h --- grx245-1/include/libbcc.h Sat Dec 22 14:02:42 2001 +++ grx/include/libbcc.h Thu Jun 27 12:59:38 2002 @@ -495,6 +495,14 @@ #endif
/* ----------------------------------------------------------------- */ +#ifdef __GNUC__ +#define _BGI_STATIC_ static +#else +#define _BGI_STATIC_ +#endif +/* ----------------------------------------------------------------- */ + +/* ----------------------------------------------------------------- */ #ifdef __cplusplus #define _BGI_INLINE_ inline #elif defined(__GNUC__) @@ -503,6 +511,60 @@ #define _BGI_INLINE_ _inline #else #define _BGI_INLINE_ +#define _BGI_IPROTO_ +#endif + +/* ----------------------------------------------------------------- */ +#ifdef _BGI_IPROTO_ +_BGI_STATIC_ _BGI_INLINE_ void restorecrtmode(void); +_BGI_STATIC_ _BGI_INLINE_ int getgraphmode(void); +_BGI_STATIC_ _BGI_INLINE_ int getmaxmode(void); +_BGI_STATIC_ _BGI_INLINE_ void getmoderange(int gd, int *lomode, int *himode); +_BGI_STATIC_ _BGI_INLINE_ int graphresult(void); +_BGI_STATIC_ _BGI_INLINE_ int getx(void); +_BGI_STATIC_ _BGI_INLINE_ int gety(void); +_BGI_STATIC_ _BGI_INLINE_ void moveto(int x, int y); +_BGI_STATIC_ _BGI_INLINE_ void moverel(int dx, int dy); +_BGI_STATIC_ _BGI_INLINE_ int getbkcolor(void); +_BGI_STATIC_ _BGI_INLINE_ int getcolor(void); +_BGI_STATIC_ _BGI_INLINE_ void cleardevice(void); +_BGI_STATIC_ _BGI_INLINE_ void setbkcolor(int color); +_BGI_STATIC_ _BGI_INLINE_ void setcolor(int color);; +_BGI_STATIC_ _BGI_INLINE_ void line(int x1, int y1, int x2, int y2); +_BGI_STATIC_ _BGI_INLINE_ void linerel(int dx, int dy); +_BGI_STATIC_ _BGI_INLINE_ void lineto(int x, int y); +_BGI_STATIC_ _BGI_INLINE_ void drawpoly(int numpoints, void *polypoints); +_BGI_STATIC_ _BGI_INLINE_ void bar(int left, int top, int right, int bottom); +_BGI_STATIC_ _BGI_INLINE_ void circle(int x, int y, int radius); +_BGI_STATIC_ _BGI_INLINE_ void ellipse( int x, int y, int stangle, int endangle, + int xradius, int yradius ); +_BGI_STATIC_ _BGI_INLINE_ void arc(int x, int y, int stangle, int endangle, int radius); +_BGI_STATIC_ _BGI_INLINE_ void getaspectratio(int *xasp, int *yasp); +_BGI_STATIC_ _BGI_INLINE_ void setaspectratio( int xasp, int yasp ); +_BGI_STATIC_ _BGI_INLINE_ void getfillsettings(struct fillsettingstype *fillinfo); +_BGI_STATIC_ _BGI_INLINE_ void getfillpattern(char *pattern); +_BGI_STATIC_ _BGI_INLINE_ void sector( int x, int y, int stangle, int endangle, + int xradius, int yradius ); +_BGI_STATIC_ _BGI_INLINE_ void pieslice(int x, int y, int stangle, int endangle, int radius); +_BGI_STATIC_ _BGI_INLINE_ unsigned setgraphbufsize(unsigned bufsize); +_BGI_STATIC_ _BGI_INLINE_ struct palettetype *getdefaultpalette(void); +_BGI_STATIC_ _BGI_INLINE_ int installbgidriver(char *name, void *detect); +_BGI_STATIC_ _BGI_INLINE_ int registerfarbgidriver(void *driver); +_BGI_STATIC_ _BGI_INLINE_ int registerfarbgifont(void *font); +_BGI_STATIC_ _BGI_INLINE_ void textlinestyle(int on); +_BGI_STATIC_ _BGI_INLINE_ void setpalette(int colornum, int color); +_BGI_STATIC_ _BGI_INLINE_ void set_BGI_mode_pages(int p); +_BGI_STATIC_ _BGI_INLINE_ int get_BGI_mode_pages(void); +_BGI_STATIC_ _BGI_INLINE_ void set_BGI_mode_whc(int *gd, int *gm, + int width, int height, int colors); +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxcolor(int mode); +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxx(int mode); +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxy(int mode); +_BGI_STATIC_ _BGI_INLINE_ int setrgbcolor(int r, int g, int b); +_BGI_STATIC_ _BGI_INLINE_ void setactivepage(int p); +_BGI_STATIC_ _BGI_INLINE_ int getactivepage(void); +_BGI_STATIC_ _BGI_INLINE_ void setvisualpage(int p); +_BGI_STATIC_ _BGI_INLINE_ int getvisualpage(void); #endif /* ----------------------------------------------------------------- */
@@ -511,200 +573,202 @@ /* --- function <func> has a compatible direct linkable variant --- */ /* --- __gr_<func> that is fully compatible --- */ /* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void restorecrtmode(void) { +#if !defined(_BGI_IPROTO_) || defined(__BCCGRX_C) + +_BGI_STATIC_ _BGI_INLINE_ void restorecrtmode(void) { __gr_restorecrtmode(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getgraphmode(void) { +_BGI_STATIC_ _BGI_INLINE_ int getgraphmode(void) { return (__gr_INIT ? __gr_Mode : (__gr_Result=grNoInitGraph)); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmaxmode(void) { +_BGI_STATIC_ _BGI_INLINE_ int getmaxmode(void) { __gr_set_up_modes(); return __gr_MaxMode; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getmoderange(int gd, int *lomode, int *himode) { +_BGI_STATIC_ _BGI_INLINE_ void getmoderange(int gd, int *lomode, int *himode) { __gr_getmoderange(gd, lomode, himode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int graphresult(void) { +_BGI_STATIC_ _BGI_INLINE_ int graphresult(void) { int res = (__gr_INIT ? __gr_Result : grNoInitGraph); __gr_Result = grOk; return res; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getx(void) { +_BGI_STATIC_ _BGI_INLINE_ int getx(void) { return __gr_X; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int gety(void) { +_BGI_STATIC_ _BGI_INLINE_ int gety(void) { return __gr_Y; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void moveto(int x, int y) { +_BGI_STATIC_ _BGI_INLINE_ void moveto(int x, int y) { __gr_X = x; __gr_Y = y; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void moverel(int dx, int dy) { +_BGI_STATIC_ _BGI_INLINE_ void moverel(int dx, int dy) { moveto( getx()+dx, gety()+dy); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getbkcolor(void) { +_BGI_STATIC_ _BGI_INLINE_ int getbkcolor(void) { return __gr_colorbg; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getcolor(void) { +_BGI_STATIC_ _BGI_INLINE_ int getcolor(void) { return __gr_color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void cleardevice(void) { +_BGI_STATIC_ _BGI_INLINE_ void cleardevice(void) { __gr_cleardevice(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setbkcolor(int color) { +_BGI_STATIC_ _BGI_INLINE_ void setbkcolor(int color) { __gr_colorbg= color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setcolor(int color) { +_BGI_STATIC_ _BGI_INLINE_ void setcolor(int color) { __gr_color= color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void line(int x1, int y1, int x2, int y2) { +_BGI_STATIC_ _BGI_INLINE_ void line(int x1, int y1, int x2, int y2) { __gr_line(x1,y1,x2,y2); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void linerel(int dx, int dy) { +_BGI_STATIC_ _BGI_INLINE_ void linerel(int dx, int dy) { register int x = getx(); register int y = gety(); __gr_line(x,y,x+dx,y+dy); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void lineto(int x, int y) { +_BGI_STATIC_ _BGI_INLINE_ void lineto(int x, int y) { __gr_line( getx(), gety(), x, y); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void drawpoly(int numpoints, void *polypoints) { +_BGI_STATIC_ _BGI_INLINE_ void drawpoly(int numpoints, void *polypoints) { __gr_drawpol(numpoints, polypoints, FALSE); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void bar(int left, int top, int right, int bottom) { +_BGI_STATIC_ _BGI_INLINE_ void bar(int left, int top, int right, int bottom) { __gr_bar(left,top,right, bottom); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void circle(int x, int y, int radius) { +_BGI_STATIC_ _BGI_INLINE_ void circle(int x, int y, int radius) { __gr_circle(x,y,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void ellipse( int x, int y, int stangle, int endangle, +_BGI_STATIC_ _BGI_INLINE_ void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius ) { __gr_ellipse( x, y, stangle, endangle, xradius, yradius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void arc(int x, int y, int stangle, int endangle, int radius) { +_BGI_STATIC_ _BGI_INLINE_ void arc(int x, int y, int stangle, int endangle, int radius) { __gr_ellipse(x,y,stangle,endangle,radius,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getaspectratio(int *xasp, int *yasp) { +_BGI_STATIC_ _BGI_INLINE_ void getaspectratio(int *xasp, int *yasp) { *xasp = __gr_Xasp; *yasp = __gr_Yasp; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setaspectratio( int xasp, int yasp ) { +_BGI_STATIC_ _BGI_INLINE_ void setaspectratio( int xasp, int yasp ) { __gr_Xasp = xasp; __gr_Yasp = yasp; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getfillsettings(struct fillsettingstype *fillinfo) { +_BGI_STATIC_ _BGI_INLINE_ void getfillsettings(struct fillsettingstype *fillinfo) { fillinfo->pattern = __gr_fpatno; fillinfo->color = __gr_colorfill; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getfillpattern(char *pattern) { +_BGI_STATIC_ _BGI_INLINE_ void getfillpattern(char *pattern) { __gr_getfillpattern(pattern); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void sector( int x, int y, int stangle, int endangle, +_BGI_STATIC_ _BGI_INLINE_ void sector( int x, int y, int stangle, int endangle, int xradius, int yradius ) { __gr_sector(x,y,stangle,endangle,xradius, yradius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void pieslice(int x, int y, int stangle, int endangle, int radius) { +_BGI_STATIC_ _BGI_INLINE_ void pieslice(int x, int y, int stangle, int endangle, int radius) { __gr_sector(x,y,stangle,endangle,radius,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ unsigned setgraphbufsize(unsigned bufsize) { +_BGI_STATIC_ _BGI_INLINE_ unsigned setgraphbufsize(unsigned bufsize) { return __gr_setgraphbufsize(bufsize); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ struct palettetype *getdefaultpalette(void) { +_BGI_STATIC_ _BGI_INLINE_ struct palettetype *getdefaultpalette(void) { return &__gr_EGAdef; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int installbgidriver(char *name, void *detect) { +_BGI_STATIC_ _BGI_INLINE_ int installbgidriver(char *name, void *detect) { return __gr_installbgidriver(name, detect); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int registerfarbgidriver(void *driver) { +_BGI_STATIC_ _BGI_INLINE_ int registerfarbgidriver(void *driver) { return __gr_registerfarbgidriver(driver); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int registerfarbgifont(void *font) { +_BGI_STATIC_ _BGI_INLINE_ int registerfarbgifont(void *font) { return registerbgifont(font); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void textlinestyle(int on) { +_BGI_STATIC_ _BGI_INLINE_ void textlinestyle(int on) { __gr_TextLineStyle = on; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setpalette(int colornum, int color) { +_BGI_STATIC_ _BGI_INLINE_ void setpalette(int colornum, int color) { __gr_setpalette(colornum,color); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void set_BGI_mode_pages(int p) { +_BGI_STATIC_ _BGI_INLINE_ void set_BGI_mode_pages(int p) { __gr_set_BGI_mode_pages(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int get_BGI_mode_pages(void) { +_BGI_STATIC_ _BGI_INLINE_ int get_BGI_mode_pages(void) { return __gr_get_BGI_mode_pages(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void set_BGI_mode_whc(int *gd, int *gm, +_BGI_STATIC_ _BGI_INLINE_ void set_BGI_mode_whc(int *gd, int *gm, int width, int height, int colors) { __gr_set_BGI_mode_pages(1); __gr_BGI_w = width; @@ -715,48 +779,49 @@ }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxcolor(int mode) { +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxcolor(int mode) { /* works like getmaxcolor() for mode */ return __gr_getmodemaxcolor(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxx(int mode) { +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxx(int mode) { /* works like getmaxx() for mode */ return __gr_getmodemaxx(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxy(int mode) { +_BGI_STATIC_ _BGI_INLINE_ int getmodemaxy(int mode) { /* works like getmaxy() for mode */ return __gr_getmodemaxx(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int setrgbcolor(int r, int g, int b) { +_BGI_STATIC_ _BGI_INLINE_ int setrgbcolor(int r, int g, int b) { return __gr_setrgbcolor(r,g,b); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setactivepage(int p) { +_BGI_STATIC_ _BGI_INLINE_ void setactivepage(int p) { __gr_setactivepage(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getactivepage(void) { +_BGI_STATIC_ _BGI_INLINE_ int getactivepage(void) { return __gr_getactivepage(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setvisualpage(int p) { +_BGI_STATIC_ _BGI_INLINE_ void setvisualpage(int p) { __gr_setvisualpage(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getvisualpage(void) { +_BGI_STATIC_ _BGI_INLINE_ int getvisualpage(void) { return __gr_getvisualpage(); }
+#endif /* ----------------------------------------------------------------- */
#endif diff -Nru3 grx245-1/src/bgi/bccgrx00.h grx/src/bgi/bccgrx00.h --- grx245-1/src/bgi/bccgrx00.h Thu Apr 19 04:20:52 2001 +++ grx/src/bgi/bccgrx00.h Thu Jun 27 12:41:20 2002 @@ -103,7 +103,13 @@ #define IMAGE_CONTEXT_SIZE (((sizeof(GrContext)+15)&~15)+4)
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void __gr_Reset_ClipBox(void) +#ifdef __BGI_IPROTO__ +_BGI_STATIC_ _BGI_INLINE_ void __gr_Reset_ClipBox(void); +#endif + +#if !defined(__BGI_IPROTO__) || defined(__BCCGRX_C) + +_BGI_STATIC_ _BGI_INLINE_ void __gr_Reset_ClipBox(void) { if (__gr_clip) GrSetClipBox( VL, VT+PY, VR, VB+PY); else @@ -113,6 +119,8 @@ GrResetClipBox(); #endif } + +#endif
/* ----------------------------------------------------------------- */
Hi Dimitar,
you should use macros here:
header: void moveto(int x, int y); #define moveto(x,y) do { __gr_X = (x); __gr_Y = (y); } while (0)
source: void (moveto)(int x, int y) { moveto(x,y); }
It's simple, clear (hmm...) and portable
Hartmut
Hartmut Schirmer wrote:
you should use macros here:
I was about to, but decided to keep the static inlines. Don't ask me why - don't know...
It's simple, clear (hmm...) and portable
It's much better that the bloated $subject in any case.
Anyway I'll rewrite it with macros, except for a function or two, which are (IMHO) too big for inlining. Getting rid of static inline / _BGI_INLINE_ is worth some more work.
E-gards: Jimmy