Autor Tema: Module MACRO's and version define  (Leído 3373 veces)

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Module MACRO's and version define
« en: Enero 29, 2009, 01:48:30 pm »
Currently you have to specify the name of the module whenever you use a module MACRO, like __bgdexport or LOCINT32. However, using correct MACRO expansion, this can be made easier.

For example for __bgdexport and LOCINT32:
Código: [Seleccionar]
#define DLLNAME mod_map

#undef __bgdexport
#define __bgdexport(a) x__bgdexport(DLLNAME,a)
#define x__bgdexport(d,a) y__bgdexport(d,a)
#define y__bgdexport(m,a)    m##_##a

#undef LOCINT32
#define LOCINT32(p,v) xLOCINT32(DLLNAME,p,v)
#define xLOCINT32(d,p,v) yLOCINT32(d,p,v)
#define yLOCINT32(m,a,b)   (*(int32_t  *)LOCADDR(m,a,b))

Another thing: -DVERSION=\"0.93\" is used (and other strings), however, I believe this is not portable to every compiler. A solution is -DVERSION=0.93 and use:
Código: [Seleccionar]
#define STRINGIFY(s) xSTRINGIFY(s)
#define xSTRINGIFY(s) #s
and then use STRINGIFY(VERSION) to get "0.93".
I didn't have problems with this until recently when I used a GCC for GP2X.
-- Sandman

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12960
  • Karma: 378
Re: Module MACRO's and version define
« Respuesta #1 en: Enero 29, 2009, 02:39:25 pm »
little weired...

indirect use of ## not works in all gnu compilers... of fact, I can't didn't works it... I was say you this time ago... I was tried use it when I made the first bgdexport... and it don't works...

but, # can be used indirectly...

the ##_## expand of this give 'd_a' and not 'mod_map_a'... ## in defines expand the literal arguments...

take a look of this http://en.wikipedia.org/wiki/C_preprocessor
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: Module MACRO's and version define
« Respuesta #2 en: Enero 29, 2009, 02:49:29 pm »
Yeah I remember our chat when you first made it, but I don't remember whether you used another indirection or not. This works for me (mingw gcc 3.4.5) anyway. If it doesn't work for you, then it cannot be used. Damn! :(
-- Sandman

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12960
  • Karma: 378
Re: Module MACRO's and version define
« Respuesta #3 en: Enero 29, 2009, 03:04:35 pm »
oh, no... I now remember... indirection works... don't works this...

Código: [Seleccionar]
#define DLLNAME mod_map

#undef __bgdexport
#define __bgdexport(a) ___bgdexport(DLLNAME,a)
#define ___bgdexport(m,a)    m##_##a

2 (defines) and DLLNAME was not expanded, it's used as literal....

but, I don't tried with 3 defines...

Código: [Seleccionar]
#define DLLNAME mod_map

#undef __bgdexport
#define __bgdexport(a) ___bgdexport(DLLNAME,a)
#define ___bgdexport(d,a) ____bgdexport(d,a)
#define ____bgdexport(m,a)    m##_##a

maybe this can works... I'll try it... thanks...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: Module MACRO's and version define
« Respuesta #4 en: Enero 29, 2009, 03:19:43 pm »
Yes, exactly. Because in ___bgdexport, the MACRO DLLNAME is expanded to mod_map and THEN passed to ____bgdexport, which concatenates it. As far as I know this should work. :)
-- Sandman

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12960
  • Karma: 378
Re: Module MACRO's and version define
« Respuesta #5 en: Enero 29, 2009, 03:56:46 pm »
I think so...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2