C-like for() statement using macros

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

Re: C-like for() statement using macros

Post by dodicat »

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: 1641
Joined: Jun 04, 2005 9:51

Re: C-like for() statement using macros

Post by dafhi »

my bad. i forgot to swap :)
Post Reply