cppo icon indicating copy to clipboard operation
cppo copied to clipboard

How to define a macro with value via command line?

Open db4 opened this issue 10 years ago • 3 comments
trafficstars

I must be missing something but cppo -D VAL=1 test.ml doesn't work:

let x = VAL

is expanded into

#1 "test.ml"
let x =  
#1      
        =1

db4 avatar Aug 27 '15 15:08 db4

The command line for that is cppo -D 'VAL 1'. If I remember correctly, it was simpler to implement that way so I didn't bother supporting the usual cpp syntax. In hindsight it was a bad decision.

mjambon avatar Aug 27 '15 17:08 mjambon

I see. But maybe to support both -D 'VAL 1' and -D VAL=1? It shouldn't be that hard.

And it would be great if the syntax was mentioned in the docs.

db4 avatar Aug 28 '15 06:08 db4

I added an example to the command-line help.

I'm hesitant to support the = syntax. Reasons are:

  • supporting two syntaxes for the same thing isn't great
  • it's inconsistent with the syntax used inside files, where no equal sign is used
  • it introduce an incompatibility, e.g. -D 'EQ =' has now a new meaning

None of this is a big deal. Maybe we can support both syntaxes but deprecate the space-based syntax.

mjambon avatar Aug 28 '15 18:08 mjambon