I want to use an element of a multi-dimensional array as a parameter to a macro, e.g.:
------------------------------------------------ program test(output);
{$define THING(a,b) writeln(a*b)}
var num : array [0..1,0..1] of integer = ((1,2), (3,4)); begin THING(num[1,1], 6) end. ------------------------------------------------
But this gives me an error: test.pas:8: macro `THING' used with too many (3) args
Presumably it's taking the first comma as an argument delimiter.
Can I get around this?
Steve Loft wrote:
I want to use an element of a multi-dimensional array as a parameter to a macro, e.g.:
program test(output);
{$define THING(a,b) writeln(a*b)}
var num : array [0..1,0..1] of integer = ((1,2), (3,4)); begin THING(num[1,1], 6) end.
But this gives me an error: test.pas:8: macro `THING' used with too many (3) args
Presumably it's taking the first comma as an argument delimiter.
Should this be changed? Using parentheses, as Eike suggested, works, but perhaps it would be more convenient if the above works. OTOH, it would (slightly) reduce the functionality of macros since it would then not be possible to use unbalanced brackets in arguments (though this is probably not useful unless in very strange situations)...
Frank
On Tue, 6 Feb 2001, Frank Heckenbach wrote:
Steve Loft wrote:
I want to use an element of a multi-dimensional array as a parameter to a macro, e.g.:
program test(output);
{$define THING(a,b) writeln(a*b)}
var num : array [0..1,0..1] of integer = ((1,2), (3,4)); begin THING(num[1,1], 6) end.
But this gives me an error: test.pas:8: macro `THING' used with too many (3) args
Presumably it's taking the first comma as an argument delimiter.
Should this be changed? Using parentheses, as Eike suggested, works, but perhaps it would be more convenient if the above works. OTOH, it would (slightly) reduce the functionality of macros since it would then not be possible to use unbalanced brackets in arguments (though this is probably not useful unless in very strange situations)...
Frank
This works:
{$define THING(a,b,c) writeln(a,b*c)} [..] THING(num(1,1), 6)
This might be a tad easier to read:
{$define THING(a,b,c) writeln((a,b)*c)}
Writing macros is tricky. Changing the rules might cause more problems then it solves.
my .02 Russ