473,230 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 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 2532
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: andylcx | last post by:
Hi all, I wrote a class, but met some exception when I call its member function. How to fix it? Thanks. My code is shown below: class Myclass { public: Myclass(); ~Myclass(); double...
3
by: Allerdyce.John | last post by:
Hi, In my code, I have a function which has a return value in the declaration: bool myFunction( int a) { // my implmentation }
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
2
by: info | last post by:
Hi... I want to know (inside a function) if the calling code wants a return value or not. Here is an example: function foo() {
3
by: mikerich135 | last post by:
Is it possible that any function without return type and returning value will return any value. If so, How?
5
arunmib
by: arunmib | last post by:
Hi all, Before posting my question I would like to state that "I am novice in VB, rather to say I am learning VB. My previous coding experience has been with C/C++". Ok, now to the question....
4
by: Polaris431 | last post by:
If I have a method like this: private void DoSomething() { try { return true; } catch{} finally
1
by: feariel | last post by:
hi, i am a beginner in programming and new to c# as well. i am using c# to access an access database that has one table named people. the table has three columns: firstName lastName TZ. i...
10
by: kobe382 | last post by:
I want to write a program to control the action of a chocolate machine. Displaying a message to ask what kind of chocolate is required: Plain (30p), Brazil nut (35p), Luxury (50p). Us on the...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.