getting return value from function without return statement.
Because of pre-ANSI C, it is possible to have a function without specifying
return type of a function (which makes the return type 'int', though) and
give no 'return' statement. For example:
foo(int a, int b)
sum = a + b;
int i = foo(1, 2);
In above code, the 'i' variable in bar() will have no useful value.
But what does the standard says? I overlooked the ISO C standard, but
found no mention about this problem.
Is this a kind of 'undefined bebavior'? Or 'unspecified behavior'?
If there's wrong point on my explanation, please enlighten me. ;-)
Or, could you give me the section number of ISO C document where it deals
with such case?
Re: getting return value from function without return statement.
firstname.lastname@example.org (Seong-Kook Shin) wrote:
> foo(int a, int b)
> int sum;
> sum = a + b;
> int i = foo(1, 2);
> In above code, the 'i' variable in bar() will have no useful value.
> But what does the standard says?
That it invokes undefined behaviour (which is worse than having no
useful value; it could crash, for example):
# 12 If the } that terminates a function is reached, and the value of
# the function call is used by the caller, the behavior is undefined.
That's from 6.9.1.
|All times are GMT. The time now is 08:10 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.