Page 1 of 1

PostPosted: Sun Aug 18, 2002 4:48 am
by darwin
Hi - I haven't posted a thing for some time... Well but I found out that PocketC supports macros. This is quite usefull:

<pre id=code><font face=courier size=2 id=code>
#define Forto (i,start,end) for(i=start;i < end;i++)

#define RECT pointer
#define RECT_init(p,x,y,w,h) p=malloc(4);p[0]=x; p[1]=y; p[2]=w; p[3]=h

#define RECT_free(p) free(p)
#define RECT_x(p) p[0]
#define RECT_y(p) p[1]
#define RECT_w(p) p[2]
#define RECT_h(p) p[3]
#define RECT_set(p,x,y,w,h) p[0]=x; p[1]=y; p[2]=w; p[3]=h
#define RECT_draw(p,x,y) rect(p[0],p[1],p[0]+p[2],p[1]+p[3])
#define GREY(i) i,i,i
main () {
int i;
Forto(i,0,40) {

</font id=code></pre id=code>

This is a simple example (i think it works - just typed it).
I think (haven't benched it) it is faster in runtime because it access everything directly without function calls. The other thing is - it is simpler. For example I have written a macros.pc file that contains some general macros - reading files into a string etc.
If you write structures or linked lists it is usefull to work without the [] brackets (as seen in the example).
I wrote this because the documentation doesn't say anything about this feature.

PS.: take a look on my photos from Korsika:

Edited by - darwin on 08/17/2002 23:50:19