MacroIf
-
- Enthusiast
- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
Re: MacroIf
I don't get it? Macros are definitions... what you're asking is like asking
for DimIf... care to explain what I'm obviously misunderstanding?
for DimIf... care to explain what I'm obviously misunderstanding?

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
Code: Select all
Macro MidU(a, b, c=-1)
MacroIf c = -1
Mid(a, b, Len(a) - b + 1)
MacroElse
Mid(a, b, c)
EndMacroIf
EndMacro
String.s = "Hallo du da"
Debug MidU(String, 4, 3)
Debug MidU(String, 4)
itself!

My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
I like this.
I thought you meant something else when first I saw your post (if macro defined ..)
So .. the compiler actually builds two (or more) sets of code and tests to see which to use at runtime? Nifty. It would makes some things Macro-able that currently are not. As per your example.l
I thought you meant something else when first I saw your post (if macro defined ..)
So .. the compiler actually builds two (or more) sets of code and tests to see which to use at runtime? Nifty. It would makes some things Macro-able that currently are not. As per your example.l
@}--`--,-- A rose by any other name ..
Code: Select all
Macro MidU(a, b, c=-1)
If (c=-1)
a = Mid(a, b, Len(a) - b + 1)
Else
a = Mid(a, b, c)
EndIf
EndMacro
String.s = "Hallo du da"
MidU(String, 4) : Debug String
MidU(String, 4, 3) : Debug String
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
-
- Enthusiast
- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
-
- Enthusiast
- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
In Deinem Beispiel würde das ja funktionieren, und der Compiler müsste nur einen der beiden Aufrufe in den Code einsetzen. Wenn nun aber der dritte Parameter eine Variable ist, dann müsste der Compiler im Code eine If/Else-Abfrage einsetzen ... und in diesem Fall würde folgendes ausreichen:FloHimself wrote:Ever played with the fasm macros? They seem more powerful then asmCode: Select all
Macro MidU(a, b, c=-1) MacroIf c = -1 Mid(a, b, Len(a) - b + 1) MacroElse Mid(a, b, c) EndMacroIf EndMacro String.s = "Hallo du da" Debug MidU(String, 4, 3) Debug MidU(String, 4)
itself!
[edit]OK (have to translate it):
In your example this would work and the compiler would replace the code by one of the MID-calls. But if the macro is "called" with a variable (and not with a constant, than the compiler has to insert an if-else ... and for this the following macro would be ok too:
[/edit]
Code: Select all
Macro MidU(a, b, c=-1)
If c = -1
Mid(a, b, Len(a) - b + 1)
Else
Mid(a, b, c)
EndIf
EndMacro
[edit]Translation:
Yes, your version would result in more optimized code!
cu, helpy
-
- Enthusiast
- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
Nope. If the macro is called with only 2 parameters the macro shouldhelpy wrote:But if the macro is "called" with a variable (and not with a constant, than the compiler has to insert an if-else ... and for this the following macro would be ok too:
evaluate to :
Code: Select all
Mid(a, b, Len(a) - b + 1)
should evaluate to:
Code: Select all
Mid(a, b, c)
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0