471,591 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,591 software developers and data experts.

getting return value from function without return statement.

Hi.

Just curiocity,

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)
{
int sum;
sum = a + b;
}

void
bar(void)
{
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?
Nov 14 '05 #1
1 2424
ta*******@yahoo.co.kr (Seong-Kook Shin) wrote:
foo(int a, int b)
{
int sum;
sum = a + b;
}

void
bar(void)
{
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.

Richard
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by andylcx | last post: by
3 posts views Thread by Allerdyce.John | last post: by
20 posts views Thread by lovecreatesbeauty | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.