Function Vs. Void

Posted By: DLively

Function Vs. Void - 03/20/15 23:50

And in this corner...

No but seriously.. what is the difference in the two, and the advantages / disadvantages between the two - Ex. are there any limitations?
Posted By: alibaba

Re: Function Vs. Void - 03/21/15 00:31

Nothing I guess. As far as I know "function" is a relict from the C-Script (WDL) age.
Posted By: Ch40zzC0d3r

Re: Function Vs. Void - 03/21/15 00:38

void cant return anything aka 0xC3 in assembler
Function is equivalent to var, meaning you can return a var aka 0xC2 in assembler.
0xC2 is followed by a WORD (2 bytes) with parameter count in bytes to clear the stack (if its stdcall, fastcall or thiscall)
Posted By: DLively

Re: Function Vs. Void - 03/21/15 00:54

Hmm... So if I understand you correctly, a void can't have void(VECTOR* temp) but 'function()' can.

edit: Because if the function returns a parameter, it can be temp = function(temp); but temp = void(temp); is not allowed?
Posted By: Ch40zzC0d3r

Re: Function Vs. Void - 03/21/15 09:02

A void cant return a value, a function can return a var value, thats the difference.
Posted By: DLively

Re: Function Vs. Void - 03/21/15 09:42

awesome. Im Glad I finally got this covered up... I've been wondering about that for some time but never got around to asking the question... Thanks Cha0zzC0d3r laugh
Posted By: MasterQ32

Re: Function Vs. Void - 03/21/15 09:51

function is just an alias for var.
Both are defined with as fixed:
Code:
typedef fixed var;
typedef fixed function;


So you can actually do this:
Code:
function a, b;
a = 10;
b = 20;
printf("%f", a + b);



Regards
Posted By: DLively

Re: Function Vs. Void - 03/21/15 10:05

MIND BLOWN laugh
Makes perfectly good sense in combination with the above answer.
Posted By: MasterQ32

Re: Function Vs. Void - 03/21/15 10:51

Sometimes its a good thing to look at your include files wink
There you can learn much about the engine itself
Posted By: alibaba

Re: Function Vs. Void - 03/21/15 11:32

Well I was wrong then grin
Posted By: WretchedSid

Re: Function Vs. Void - 03/21/15 12:40

The compiler doesn't enforce the return type though, so you can still return values from a void function and have the compiler care fuck all about it.

Also, Lite-C from my limited experience uses cdecl as calling convention, which uses 0xc3 (aka the ret instruction) and carries the return value for simple integers in the EAX register. retl, retw, retq etc (0xc2) are rarely if ever used as the compiler can either easier create code that has the result in the EAX register already or add a mov which can be done in one byte, making the whole thing use less space either way laugh
© 2024 lite-C Forums