Hi, the topic says all, its possoble?

Well D???????????????????????????????????????ne!
Posted on 2003-05-18 08:41:01 by Forginforcer
*yawn* asm is no hll. Thus, I doubt the above is possible.
Posted on 2003-05-18 09:16:36 by roticv
I'm not sure exactly what you mean, but look up
VARARG in your MASM references.
Posted on 2003-05-18 09:29:06 by anon
in c++ ist possible...
Posted on 2003-05-18 09:32:15 by Forginforcer
Try it and see what happens:grin:

best regards

czDrillard
Posted on 2003-05-18 09:34:31 by czDrillard
I dont want to make something wrong.
I have got a server and i dont want to let crash it.
Its at the moment off, but i'm veryy afraid! :grin: :grin: :grin:

Jokes by side, i will test it!
Posted on 2003-05-18 10:05:29 by Forginforcer
function overloading in eg C++ is handled through name mangling, so at object/linker level, the function names are no longer the same.
Posted on 2003-05-18 10:29:53 by f0dder
error A2111: conflicting parameter definition :eek:
Posted on 2003-05-18 10:30:54 by Forginforcer
so its defenitiv not possible to do that ?
Posted on 2003-05-18 10:31:48 by Forginforcer

so its defenitiv not possible to do that ?
Only with MACROs is it possible and it is MUCH work to get right - may as well build a new assembler.
Posted on 2003-05-18 11:12:47 by bitRAKE
No MASM is pretty coool !

A nother way would be to create a programm, wich get startet before the assembler wich changes the programm names.

But I will leave it, I will give the funktion diferent names.
Posted on 2003-05-18 11:15:36 by Forginforcer
Afternoon, Forginforcer.

As anon suggested, you can do it using VARARG.

However... you will still need to tell your code what to do.

One way would be to use the first arg to tell your proc how many args there are in total.
Another way would be to do what wsprintf seems to do, and that is to know how many extra args there are depending upon the supplied formatting string.

Note that this isn't the same as how you do it in C++.
As f0dder has mentioned, the C++ compiler mangles the names of the various functions which have the same name so that in the end, no function actually has the same name (it's done transparently so you never know it's doing this).

With asm and VARARG, you'll have to do everything within the same proc.

The prototype could be possibly:


myFormattingProc PROTO C :DWORD, :DWORD, :VARARG


The proc itself, if using a formatting string to grab the number of args, could be something like this:


myFormattingProc PROC C outputbuffer:DWORD, formatstring:DWORD, args:VARARG
.data
mylittlebuffer db 128 dup (0)
thefMtStrinG db "%lu",0
.code


; first arg is a pointer to a buffer
; second arg is a pointer to a string with formatting info
; the number of extra args is dependant upon how many %'s are in the formatting string

push esi
push edi
mov esi, formatstring
mov edi, outputbuffer

xor edx, edx ; offset to formatting args
@formatbuffer:

lodsb ; grab the byte at esi

cmp al, '%' ; is it a formatting character?
jnz @storechar ; nope

lodsb ; yep, so find out what type of data this is
cmp al, 'd' ; it's a number?
jnz @nexttype ; nope

push edx ; "wsprintf" destroys our offset value, so save/restore it
lea eax, args
add eax, edx
invoke wsprintf, ADDR mylittlebuffer, ADDR thefMtStrinG, DWORD PTR [eax]
push esi
mov esi, offset mylittlebuffer
invoke lstrlen, ADDR mylittlebuffer
mov ecx, eax
rep movsb

pop esi
pop edx

jmp @grabnextchar

@nexttype:
; check for next type of possible data
; since this proc only handles numbers (%d) ...
; return an empty buffer if we find something
; we don't know how to handle
mov edi, outputbuffer
mov BYTE PTR [edi], 0
pop edi
pop esi
ret

@grabnextchar:

add edx, 4 ; update offset to next possible formatting arg
jmp @formatbuffer

@storechar:
stosb ; store character in outputbuffer
cmp al, 0 ; finished?
jnz @formatbuffer ; nope. check next character

pop edi
pop esi

ret
myFormattingProc ENDP


And you'd call it like so:


.data
szOK db "OK",0
szoutputbuffer db 256 dup (0)
szformatstring db "1st Arg:%d",13,10,
"2nd Arg:%d",13,10,
"3rd Arg:%d",0
.code
invoke myFormattingProc, ADDR szoutputbuffer, ADDR szformatstring, 10, 5, 243
invoke MessageBox, NULL, ADDR szoutputbuffer, ADDR szOK, MB_OK


Cheers,
Scronty
Posted on 2003-05-18 11:24:36 by Scronty
WOW:alright:

Thanks, looks very interisting!
Posted on 2003-05-18 11:46:59 by Forginforcer
Use JAVA :tongue:
Posted on 2003-05-18 11:55:56 by bazik
I do not understand what you tip should be? bazik!

I want to programm in JAVA
Posted on 2003-05-18 12:18:14 by Forginforcer

function overloading in eg C++ is handled through name mangling, so at object/linker level, the function names are no longer the same.


amm i have a question, the the names are changed, ok, but how are they exported??, like i understand for example if you use.. for example:

global _externlabel ;this with 4 dword args
_externlabel:

global _externlabel ;this only with 3
_externlabel:

i think here i will obtain a error, remember that function overloading works only for the param count/the diference of the arguments...

eg void uno(int); void uno(char); can be but void uno(int) int uno(int) can't

mm i think the solution if i dont understand bad.. is @numberOfBytesOfTheArgs eg:

global _externlabel@16 ;this with 4 dword args
_externlabel@16:

global _externlabel@12 ;this only with 3
_externlabel@12:


But here is a problem i think.. what append if two diferent proc at the end have the same number of bytes in theis arguments???, how is this handled, eg void uno(DWORD); void uno(WORD, WORD);


mmm, ok the other question is.. if i do some like that??, how i can link?? for example if in other file i want call _externlabel, WORD1, WORD2 how the linker know what of the both are and not call the wrong???

== how i can refer to a specific label, only callin the name, without the count.. and if is the correct count.. how i distingue betwen the diferent types of data???
Posted on 2003-05-18 13:26:47 by rea
Afternoon, hgb.

== how i can refer to a specific label, only callin the name, without the count.. and if is the correct count.. how i distingue betwen the diferent types of data???

You can't.
That is a feature of C++, not asm.
The compiler would have to understand the differences between data types (Float, Unsigned Char, Int, etc) to be able to mangle the function names correctly. It doesn't just go by the param count.
A normal C function != overloaded C++ function.

It would be a huge job to build a preprocessor for an asm file to mangle up overloaded procs.

Far easier to just send the same proc a variable to tell it which section of code to execute.
i.e. myProc proc C versiontype:DWORD, args:VARARG
where "versiontype" could be:
1 for a single param: a single int;
2 for two params: two floats;
3 for varied params, but two minimum: an output string, a formatting string, and varied number of args for formatting.

Cheers,
Scronty
Posted on 2003-05-18 17:22:13 by Scronty