C language #define # and ## operators use

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 42270
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

C language #define # and ## operators use

Post 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

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
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply