C language #define # and ## operators use

C language #define # and ## operators use

Postby Antonio Linares » Tue Oct 24, 2023 7:20 am

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Return to Off Topic / Otros temas

Who is online

Users browsing this forum: No registered users and 25 guests