tags:

views:

69

answers:

1

I am trying to force gnu - cpp to keep special comments like /*+ ... / because I need them for optimiser hints. It worked well with cpp of xlc (AIX) but now I get an addtional space between slash and plus (/) ?

e.g.:

$ cat cpp-test.sql
#define _STAR *
#define OPT_HINT(x) /_STAR+ x _STAR/

select OPT_HINT(INDEX(TABLE table_pk)) * from table

$ /usr/bin/cpp -E < cpp-test.sql
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"

select / *+ INDEX(TABLE table_pk) */ * from table

$

I would desire to get "select /*+ INDEX(TABLE table_pk) */ * from table".

Any suggestions ?

Best regards

Dirk

+2  A: 

You can paste tokens together using the ## preprocessor operator:

#define F foo
#define B bar

F##B

produces

foobar

But note that cpp is intended to be the C (and C++) pre-processor - it is not supposed to be a general purpose tool. If you really want to do this sort of stuff, take a look at alternative macro processors, such as m4.

Also note that building comments will not work for C or C++ code, as they are processed in a different pre-processor phase from macros.

anon