Nandan
6th July 2007, 23:00
I am trying to understand how token passing mechanism in case of compiler preprocessor works, however I found very little explanation on this topic.

Probably the best examples of token passing can be seen if you compile the exchange scheme in debug mode, and go through the generated script.

This is an example I have taken from one of the scripts generated by exchange

In the initial part of script we have this block


#define BatchLineList1(batl.stmt)
^ batl.stmt( 1, 1,MAP , 10,tcmcs045, 1)
^ batl.stmt( 2, 2,MAP , 20,tcibd001, 1)


below this block we have


| Tables
#define TtblDecl(d1, d2, d3, d4, ttbl, d6) table t##ttbl
BatchLineList1(TtblDecl)

#define InitBatlVars(i, c.ind, cxch, batl, ttbl, indx)
^ b.cxch(1, i) = "cxch"
^ b.batl(i) = batl
^ b.ttbl(1, i) = "ttbl"
^ b.cind(i) = c.ind
^ b.indx(i) = indx

function sub.init.batl1()
{
BatchLineList1(InitBatlVars)
}


|************************************************************************
|********************* Functions per iBaan ERP table ********************
|************************************************************************

function extern create.tables()
{
#define TtblCreate(i, d2, d3, d4, ttbl, d6)
^ db.create.table(t##ttbl##)
^ b.tbid(i) = t##ttbl

long save.bypass

commit.transaction()
save.bypass = error.bypass
error.bypass = 1
BatchLineList1(TtblCreate)
commit.transaction()
error.bypass = save.bypass
}



I am trying to understand how this works. If anybody has explanation or can explain Layman English it would be great help.

NPRao
7th July 2007, 02:17
Here's the info from the Tools Programmer's Manual - Token pasting (preprocessor) (http://www.baanboard.com/programmers_manual_baanerp_help_3gl_features_token_pasting_preprocessor)

Perhaps, these links will give you some more info: Token-Pasting Operator (##) (http://msdn2.microsoft.com/en-us/library/ms880143.aspx), Token Concatenation (http://en.wikipedia.org/wiki/C_preprocessor)