On the core topic:

// let's assume you have a bunch of functions like
// long ReturnSum(long x,long y); or
// long ReturnMul(long x,long y);

typedef long(*operacia)(long, long);

operacia Operate[]={
ReturnSum,
ReturnMul
};

Then you'll do:
Operate[0](x,y); // for sum
Operate[1](x,y); // for multiplication

long opi,result;
... fill opi with something here
result = Operate(x,y);

if in your code you can't completely control the "opi" variable.. That is if we get opi=2 here, you'll get a GPF. If the operations are not in complete consecutive order, you'll have to make a lookup table to see which case what operation is - which can also be a bit slow unless you do a partition search of the sorted entries. - like in the switch macro posted at this board.

Comments in asm should be in my style :-D :



;----[ parse arguments ]--------------------------\
.if !pDest
m2m pDest,FocusedWorkspace
.endif
.if !pSrcWorkspace
m2m pSrcWorkspace,FocusedWorkspace
.endif
mov eax,pSrcWorkspace
cmp eax,pDest
je _ret ; can't move from one place to the same
;-------------------------------------------------/

;----[ show or hide windows if necessary ]------------\
mov eax,pSrcWorkspace
.if eax==FocusedWorkspace
foreach pSrcWorkspace,invoke ShowWindow,EDX,SW_HIDE
.endif
mov eax,pDest
.if eax==FocusedWorkspace
foreach pSrcWorkspace,invoke ShowWindow,EDX,SW_SHOW
.endif
;-----------------------------------------------------/

; delete all windows from pSrc, insert them in pDest
foreach pSrcWorkspace,multi icall pSrcWorkspace,ObjVector,delete,EDX | icall pDest,ObjVector,insert,EDX

Posted on 2005-01-08 14:24:39 by Ultrano
Seems like a pretty decent commenting style, Ultrano - comment blocks rather than every line, use comments to show the outlines of the blocks, and comment individual lines where necessary. :alright:
Posted on 2005-01-08 14:26:53 by f0dder
Block comments are usually an indication that the code can be refactored to smaller functions...
That mostly applies to high level languages, though.
Posted on 2005-01-09 02:08:13 by death
Worst code in asm must be when you are running out of registers and need to use
both vars. and nasty push&pop's everywhere. I have spent some time figuring
out what the hell I was doing in some functions..  :lol:
Posted on 2005-04-27 07:09:04 by bubach