C-like for() statement using macros

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
dodicat
Posts: 5880
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: C-like for() statement using macros

Postby dodicat » Aug 22, 2018 9:35

With -gen gcc (all these loops (while,for,do) are parsed to GOTO LABEL in the c code.
-gen gcc -Wc -O3 for example.
But after that it's up to the team at gcc HQ what happens next.
Even Fibonacci .

Code: Select all

 #macro forloop(a,b,c,instruction)
scope
a
#define labl  label:
labl
instruction
c
if b then goto labl
#undef label
end scope
#endmacro

dim as ulongint acc,ctr

forloop(dim as ulongint x=0,x<=5000000000000000000,x+=acc-(x-2)-(x-1),acc+=(x-1):ctr+=1:print ctr;tab(5);acc+1)
 
forloop(dim as long p=0,p<24,p+=1,print "=";)
 print
 sleep 
dafhi
Posts: 1241
Joined: Jun 04, 2005 9:51

Re: C-like for() statement using macros

Postby dafhi » Aug 22, 2018 13:25

my bad. i forgot to swap :)

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests