Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with macros
#1
I get all kinds of strange errors (fb 0.13) like "Variable not declared, found: 'Pa' on line 186"

I have tested the Min8 (7,6,5...2) macros, and they work with constants (like Min3(100, 50, 64) returns 50).

But when I put a bit more advanced code into it, it gives me compilation errors.

If anybody could take a look at http://www.rafb.net/paste/results/o4Ezuk90.html (line 9-15 and line 183-186) and tell me if I'm doing anything wrong or it's a compiler error (v1c).

If anybody has any alternative ways of making a Min/Max function, go ahead and post that too.

Thanks Smile
Reply
#2
I guess it's because the max size of expanded macros, that was set to 1024 at lex.bas. When a macro is used inside another macro it gets expanded and each argument found on macro's body is replaced by a pattern that takes 6 bytes, to make it unique.

I will add a warning if the macro's expansion text gets too long.. making it 4x more will help too, PB has a 4096 bytes limit, if i remember..
Reply
#3
Fair enough Smile

Using a couple of kilobytes here wouldn't harm anybody I suppose.

Btw, three suggestion to the standard library:
Min(a, b, c) selects the smallest of it's (any number of) arguments.
Max(a, b, c) selects the greatest of it's (any number of) arguments.
Clamp(a, b, c) returns a if it's within the range of b to c. Otherwise it returns b (if less) or c (if more).

The Clamp could be done with macros without much of a hazzle I suppose, but the Min/Max is quite tedious to make I think. It would be nice with these kind of commonly used variable argument functions in the standard library.
Reply
#4
I did this instead btw:
[syntax="freebasic"]
MinA = Min4(PathMap(X - 1, Y - 1), PathMap(X, Y - 1), PathMap(X + 1, Y - 1), PathMap(X, Y + 1))
MinB = Min4(PathMap(X - 1, Y + 1), PathMap(X - 1, Y), PathMap(X + 1, Y + 1), PathMap(X + 1, Y))
PathMap(X, Y) = Min2(MinA, MinB)
[/syntax]
Nice and lazy hehe...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)