Default return value for functions.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Default return value for functions.

Mani
Hi,

Is there a default return value defined for functions?
For instance, I write an int function (function that is supposed to
return an int), or a double function, but I forget to return a value.

still something gets returned -- how is that return value defined, if at all?

best, murali.

note: I am using Bloodshed Dev C++

------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Default return value for functions.

lrn-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02.11.2011 22:20, Mani wrote:
> Hi,
>
> Is there a default return value defined for functions? For
> instance, I write an int function (function that is supposed to
> return an int), or a double function, but I forget to return a
> value.
>
> still something gets returned -- how is that return value defined,
> if at all?
The value returned in such cases is the result of internal C Runtime
call to the Reformat_all_hard_drives_and_wipe_out_the_memory() function.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOsYx8AAoJEOs4Jb6SI2CwB7IH/jppFBtRRR2TWZ9F5AaF9Grd
S0vdzUq3GKdksXaOAv0MnRB3efrByITRgdor6VbuTzpSJvcxjfwo6nEMY+xgkUWw
vZWST9j7VUHs/app7wSRN7l15xo9QGxU9eEEVcfDv8EsXEl1z9IZZqQsG+b+5xfa
quqPCiwgU1pszQhQqNEevE2XFX7t/Kb7ovT8TFd2FfGO6aJe4TL3lbE7p0seVq1u
Cu8TAFu0v9IGeemtYkMqvf/xmR2fRHBT03u7EzU9oDoqKDr7DQZ0KfXUNCRUQhiH
9ttiRZHxqv5AV1iHQP5l/aBpbKXWcfa7spSbEkQrOHmNfXgwYJRY9Y7hqzGsl5Y=
=jqMV
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Default return value for functions.

Earnie Boyd
LRN wrote:

> On 02.11.2011 22:20, Mani wrote:
>> Hi,
>
>> Is there a default return value defined for functions? For
>> instance, I write an int function (function that is supposed to
>> return an int), or a double function, but I forget to return a
>> value.
>
>> still something gets returned -- how is that return value
>> defined, if at all?
> The value returned in such cases is the result of internal C
> Runtime call to the
> Reformat_all_hard_drives_and_wipe_out_the_memory() function.

LRN is being sarcastic.  The value returned is defined by the C
specifications for C as a language.  I assume but do not know and will
not confirm a function will return a value appropriate to its definition.

--
Earnie
-- http://www.for-my-kids.com

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Default return value for functions.

lrn-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03.11.2011 15:25, Earnie wrote:

> LRN wrote:
>> On 02.11.2011 22:20, Mani wrote:
>>> Hi,
>>
>>> Is there a default return value defined for functions? For
>>> instance, I write an int function (function that is supposed to
>>>  return an int), or a double function, but I forget to return a
>>>  value.
>>
>>> still something gets returned -- how is that return value
>>> defined, if at all?
>> The value returned in such cases is the result of internal C
>> Runtime call to the
>> Reformat_all_hard_drives_and_wipe_out_the_memory() function.
>
> LRN is being sarcastic.  The value returned is defined by the C
> specifications for C as a language.  I assume but do not know and
> will not confirm a function will return a value appropriate to its
> definition.
>
After googling a bit, i found [1], which contains the following quote
from C89:

C89 6.6.6.4 "The return statement":

"A return statement with an expression shall not appear in a function
whose return type is void. [...] A function may have any number of
return statements, with and without expressions. [...] If a return
statement without an expression is executed, and the value of the
function call is used by the caller, the behavior is undefined."

I assumed that "a function without return statement" is equivalent to
"a function with a return statement that is no followed by an
expression" (that is, "return" is placed implicitly at the end of the
function).

[1]
http://www.velocityreviews.com/forums/t711572-function-not-returning-a-value.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOstLtAAoJEOs4Jb6SI2CwHy0H/14HEBts1fno2KN0Eup6xmNa
pKZgtUFobAPOj0R/LmNo47wShQuTyW/j3EcBVlGtKIGG06L3mkM/ylXByBbhVm4j
/L4U7qEtf0mynplbBSTCy+1OXG0ZjisnNu4ZeRUNUcJvJIg+cJewUyBxA2UMy5Cm
NBixkZ6X0rz+nfd5nfyqtUK/7384XKOROHnZ3vGwwtpRweAJWUxCqaz7Nv0hVleb
w3hFe+QK+ltoP8CaHWsAJzoiKAQtKyESnhrcjog3zZxRNgzINbrgXkkcd3WNipD4
G/Nk7t2wl65PbZXiGOWTmNiEUEh+9L9v9VFV3LhpBbGWy43cVnmNDlrvrfatQ5o=
=zpj2
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Default return value for functions.

Mark Wagner
In reply to this post by Mani
On Wed, Nov 2, 2011 at 11:20, Mani <[hidden email]> wrote:
> Hi,
>
> Is there a default return value defined for functions?
> For instance, I write an int function (function that is supposed to
> return an int), or a double function, but I forget to return a value.
>
> still something gets returned -- how is that return value defined, if at all?

Typically, the compiler will specify a memory location to store the
return value in (the details depend on the calling convention in use);
if you don't include a "return" statement, the memory location will be
uninitialized, and the function's return value will be impossible to
predict.

--
Mark Wagner

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Default return value for functions.

d3x0r
In reply to this post by Mani
Chances are your C returns the result in a register; if you don't
build a return (which should be an error not a warning) then whatever
you happened to do last that set the register (often ax, eax, or
rax...et al. )   will be what your function returns;  if you change
your code and add something like a logging outptu just before the end
youc an change it.  If your last calcuioant was like lock = 0; then
probably it would be zero, but unless you return something there is no
guarantees.   Might as well return ((int(*)())printf("some
memory"))();

On Wed, Nov 2, 2011 at 11:20 AM, Mani <[hidden email]> wrote:

> Hi,
>
> Is there a default return value defined for functions?
> For instance, I write an int function (function that is supposed to
> return an int), or a double function, but I forget to return a value.
>
> still something gets returned -- how is that return value defined, if at all?
>
> best, murali.
>
> note: I am using Bloodshed Dev C++
>
> ------------------------------------------------------------------------------
> RSA&#174; Conference 2012
> Save $700 by Nov 18
> Register now&#33;
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
> Also: mailto:[hidden email]?subject=unsubscribe
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe