Macros

Previous topic - Next topic

Quentin

... could be a nice thing to make code easier to read. (especially for INLINE snippets)

Code (glbasic) Select

MACRO newcommand(var)
    INLINE
        var++;
        ...
    ENDINLINE
ENDMACRO


// use in GLBasic code
LOCAL counter%
newcommand(counter)

Schranz0r

#1
FUNCTION can do the same...

EDIT:

Code (glbasic) Select
LOCAL my_var = 10
Add(my_var)

WHILE TRUE

PRINT my_var,10,10

SHOWSCREEN
WEND
END



FUNCTION Add: BYREF var
INLINE
var++;
ENDINLINE
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Quentin

sure, but FUNCTION always does have overhead (calling, stack, ...)
Macro is a simple replacement of code, so produces bigger, but faster code.

Kitty Hello

macros are not type safe. I would have to run a pre-pre-compiler for the macros. A nice idea, though.

FutureCow

What about platform specific macros? That way you could do something like

if for iphone
  resolution = 100x200
else
  resolution = 800x600
endif