i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?
what exectly are macros?
what exectly are macros?
~Dreglor
Re: what exectly are macros?
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.
Re: what exectly are macros?
It is even possible - FASM does that for example - to replace built-in commands with own macros. There was a tip likeDreglor wrote:i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?
Code: Select all
macro inc v
{
pushf
add v,1
popf
}
macro dec v
{
pushf
sub v,1
popf
} The above works even with PB, if you let generate commented output, put the macro into the asm code and then let PB recompile the asm code. BTW, it is meant to speed optimize inc & dec for P4 (claims are that add/dec commands are faster)
What is quite common too, is the precalculation of data. Like you need an array a(0)=0 to a(99)=99. Instead of dynamically calculating it in your program or typing by hand, a macro fills the array each time you compile.
-
FloHimself
- Enthusiast

- Posts: 229
- Joined: Wed May 14, 2003 3:38 pm
- Location: Lüneburg - Germany
Code: Select all
!macro inc v
!{
!pushf
!add v,1
!popf
!}
!macro dec v
!{
!pushf
!sub v,1
!popf
!}
foo = 4
Debug foo
!dec [v_foo]
Debug foo Re: what exectly are macros?
Macros are a nice and convienient way to obfuscate and confuse code to make it unreadable by all that has not coded it!Dreglor wrote:i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?
I have always thought of macros as a sort of "inline procedure" - but expanding out the code (putting the code in place of the macro) instead of calling the function. Thus marginally faster but marginally bloatier.
eg (and taking some liberties with Pure's yet to be seen syntax):
Is this on track? Or totally wrong?
PS: I thought they improved readability!
EDIT: Lots of Apache errors happening in the forum.
eg (and taking some liberties with Pure's yet to be seen syntax):
Code: Select all
MACRO r.l = myDumbMacro a.l, b.l
local j.l
j = a * 10
r = j + b
EndMACRO
;-v-
Procedure myDumbProc(a.l, b.l)
j = a * 10
ProcedureReturn j + b
EndProcedure
result = myDumbMacro valueA, 2
; is effectively replaced with the machine code for
; local_j = valueA * 10
; result =local_ j + 2
-v-
result = MyDumbProc(valueA, 2)PS: I thought they improved readability!
EDIT: Lots of Apache errors happening in the forum.
@}--`--,-- A rose by any other name ..

