BASIC

Author Topic: Macros  (Read 2337 times)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Macros
« on: 2009-May-10 »
... 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)
 

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5003
  • O Rly?
    • View Profile
Re: Macros
« Reply #1 on: 2009-May-10 »
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
« Last Edit: 2009-May-10 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: Macros
« Reply #2 on: 2009-May-10 »
sure, but FUNCTION always does have overhead (calling, stack, ...)
Macro is a simple replacement of code, so produces bigger, but faster code.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10675
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Macros
« Reply #3 on: 2009-May-11 »
macros are not type safe. I would have to run a pre-pre-compiler for the macros. A nice idea, though.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Macros
« Reply #4 on: 2009-May-30 »
What about platform specific macros? That way you could do something like

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