Page 1 of 1

C language #define # and ## operators use

PostPosted: Tue Oct 24, 2023 7:20 am
by Antonio Linares
This is supported by C compilers, but I guess it is a quite unknown feature:

A single #name stringify the name

A double ## joins two names

Code: Select all  Expand view
function Main()

   MsgInfo( Test() )

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <stdio.h>

#define MEMBER(TYPE,NAME,MORE) TYPE NAME MORE

#define TSTRUCT(NAME,MEMBERS) \
typedef struct NAME { \
MEMBERS \
} NAME; \
const char* const NAME##_Members = #MEMBERS;

TSTRUCT(S,
 MEMBER(int,x;,
 MEMBER(void*,z[2];,
 MEMBER(char,(*f)(char,char);,
 MEMBER(char,y;,
)))));

HB_FUNC( TEST )
{
   S test;

   hb_retni( test.x );
   // hb_retc( S_Members );
}

#pragma ENDDUMP