What? Overloading functions in assembly? I bet you're thinking "he's crazy"! (Me=He) Am I? Really? If you implement the right macros anything is possible The only problem is: 1) You have to make a macro that declares that the next function called will be called with certain parameters 2) Create multiple functions* ending in _V1,_V2,... for version1,version2,etc. Document each one for parameter types and return value 3) Make a macro for the function that takes your assembly variables set in the overload declaration and makes a decision on which version of the proc to invoke. It must then clear these variables, *Under some circumstances you can convert data types instead ex)
Overload ,,
Function a,ADDR hi
mov   result,eax
The internal variables should be numeric with = so that they can be changed returntype = 0 ' void param1type = 3 ' DWORD I am thinking of how to extend this for structures and other data structures probably there would be a need for ID's of structures Any comments, suggestions, etc. Please Reply.
Posted on 2001-04-10 19:28:00 by BigBadBob
Sure, your idea seems very do-able. While I personally don't see the need to overload functions for asm work, you may prefer this technique as your style of work. Macros are made for this type of duty. A macro can check parameter types (something we tend to avoid in MASM32 loose typeing, but MASM itself may be as strongly typed as you desire). Macros make a good language extended, that's why they are there.
Posted on 2001-04-10 19:39:00 by Ernie
Ernie, The "Overload" wasn't specifically for type checking, it was more of a way to choose the proper function from the other related functions based on the stated parameters, the actual type checking would still be handed over to invoke. Maybe I should have called it "ChooseOverloadedType" because it means choose the actual function to call based on the parameters that I am stating it will recieve. (I am Mr. Idea Man) I obviously thought that this was a good idea, however I actually can't find a good application for it. This idea actually spurred from a simpler idea of rewriting the return statement included in some Masm32 example code. For example. If you use return when there is no return value then the MACRO should ECHO an error. Also, if for some reason the return value is a byte/word/qword/real then the return statement should also be able to account for each of these cases. I actually started to write this (many, many lines by the way) to take almost any situation into account. This would include makeing return bl work even if returning in eax, taking everything into account even sign. (I don't think I'll actually continue, it isn't worth it). However, if I chose to do just overloading then this would be simpler as long as return simply returns eax,ax,al,edx:eax, or reals instead of doing all of the other unneccessary stuff.
Posted on 2001-04-11 01:27:00 by BigBadBob
Now I'm not sure if you're talking about macros or procedures. But messing with the return value of a procedure is just... well, useless. Concider: How do you know WHAT is going to be returned if even the type is ambigious? And if you don't know what type is there (or where), well... you now have more questions then answers. Not something useful.
Posted on 2001-04-11 20:34:00 by Ernie
The "function call" would have to be through macros that choose the proper "actual function" to call. psuedocode:

Function MACRO params:VARARG
      Invoke Function_V1, &params&
      Invoke Function_V2, &params&
      ECHO Unable to resolve overloaded type
This message was edited by BigBadBob, on 4/12/2001 2:00:50 AM
Posted on 2001-04-12 01:53:00 by BigBadBob