Author Topic: Arity  (Read 2215 times)

nobody

  • Guest
Arity
« on: February 14, 2009, 05:14:34 AM »
Hi,

I have two functions with the same name but different number of parameters. Is there a way of dealing with this problem without changing the name of one of them, perhaps some way to determine how many parameters a function is called with?

Michael

Jim

  • Guest
Re: Arity
« Reply #1 on: February 14, 2009, 08:32:32 AM »
If one of the paramters was a parameter count, yes.  If you're working with assembly, you realize that there is a stack with parameters pushed (very often), and that there is no back reference...unless you add one youself.  C++ handles this by creating complex names beyond what you see, but working so close to the metal, you'll have to handle that yourself.  The macro processor for nasm does support knowing how many parameters... so perhaps if you wrote a function declaration macro, that could hide the name mangling of your function....

nobody

  • Guest
Re: Arity
« Reply #2 on: February 14, 2009, 12:59:41 PM »
Hi Jim,

Thanks.  I haven't done any asm macro programming yet. Is there a decent intro or tutorial?

Michael

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2381
  • Country: us
Re: Arity
« Reply #3 on: February 15, 2009, 12:50:36 AM »
There's Mammon_'s "Extending Nasm" article:

http://web.textfiles.com/ezines/APJ/apj_3.txt

It's ten years old...

As d3x0r points out, Nasm can distinguish between macros with the same name, and different numbers of parameters. This could be used to "hide" the fact that two functions had different names, but I don't think that you can "really" have two functions with the same name - not in the same file, and not in two files that are going to be linked together (with the names "global"... you could have functions with the same name in two files, but not with the names made visible, to the linker, and thus to the calling module).

Betov, the Unpleasant Frenchman, used to say that these namespace collisions should be "impossible", because the functions should have meaningful names - what Betov calls "full-talking names". If they've got the same names, they should do the same thing - and you don't need both. If they do different things, they should have different names describing what they do. Problem solved. I think he may have something there!

If you *could* get Nasm to do it, how would you keep *yourself* from being confused???

Best,
Frank