PDA

View Full Version : Default return value for functions



chronozphere
15-12-2007, 05:44 PM
Hi fellow programmers 8)

I have a small question. What is the default return value for a function??

I often see the "Return value of function ***** might be undefined". So what happens when it is undiefined? Do i get random data, or is it set to zero?

If it is possible, i would like to compile my code in such a way that all functions return 0 or NIL by default. I don't like doing this:


function SomeFunction: integer;
begin
//just to make sure, SomeFunction has a valid return value
Result := 0;

//lots of code
end;


It would save a lot of code, if i could assume that every function returns 0 by default.

Any tips?? compiler options maybe??

Thanx

JSoftware
15-12-2007, 05:58 PM
Using the standard calling convention of pascal you have the return information in eax. If your function takes any parameters eax will contain the first parameter which it'll return if you don't change it.

SomeFunction in your example will return whatever is in eax when you call it, eg. random data

chronozphere
15-12-2007, 06:25 PM
Ah thanx... didn't know that;)

User137
15-12-2007, 07:48 PM
SomeFunction in your example will return whatever is in eax when you call it, eg. random data
Can i use this info to make new random() function? ^^ hehe just joking.

Huehnerschaender
16-12-2007, 12:52 PM
Once I had an error in a commercial application I made at work.

The bug was a function that returns a boolean value.

After hundreds of tests I realized that this function returned true by default on Windows XP and false on Windows 2000.

Very strange, but since then I ALWAYS initialize functions return value in the first line of the function :)

Greetings,
Dirk

chronozphere
16-12-2007, 02:38 PM
Those are really awefull bugz. Glad you solved it. :)

Didn't you get some kinda "Return value of function ***** might be undefined" warning?? :scratch:

chronozphere
16-12-2007, 02:38 PM
EDIT: Oops! doublepost :oops: I got an error, so i reposted, but the message was allready there.