Results 1 to 7 of 7

Thread: Default return value for functions

  1. #1

    Default return value for functions

    Hi fellow programmers

    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:

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

    //lots of code
    end;
    [/pascal]

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

    Any tips?? compiler options maybe??

    Thanx
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Default return value for functions

    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
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Default return value for functions

    Ah thanx... didn't know that
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4

    Default return value for functions

    Quote Originally Posted by JSoftware
    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.

  5. #5

    Default return value for functions

    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
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  6. #6

    Default return value for functions

    Those are really awefull bugz. Glad you solved it.

    Didn't you get some kinda "Return value of function ***** might be undefined" warning?? :scratch:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Default return value for functions

    EDIT: Oops! doublepost ops: I got an error, so i reposted, but the message was allready there.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •