473,386 Members | 1,674 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,386 software developers and data experts.

not using the return value

Hi

I read an example provided by Big Bucks Inc. no how to use their
library. in it they have some thing like

string doit(){ /* ... */ cout << "doit called" << endl; }

int main(){
doit();
}
how can this be correct?
should not doit() return void? and if not, what am I missing?

thanks
Dec 8 '06 #1
6 1343

Gary Wessle wrote:
Hi

I read an example provided by Big Bucks Inc. no how to use their
library. in it they have some thing like

string doit(){ /* ... */ cout << "doit called" << endl; }

int main(){
doit();
}
how can this be correct?
should not doit() return void? and if not, what am I missing?
Or it should actually return something. It is perfectly ok to ignore a
return value but not to not return a value from a non-void function.

Dec 8 '06 #2
Gary Wessle wrote:
I read an example provided by Big Bucks Inc. no how to use their
library. in it they have some thing like

string doit(){ /* ... */ cout << "doit called" << endl; }

int main(){
doit();
}
how can this be correct?
should not doit() return void? and if not, what am I missing?
If a function returns something and another function makes no use
of that, it's perfectly OK. The return value is simply discarded
(and if it's a temporary, it's destroyed).

What seems to be dangerous (although not necessarily wrong) here
is that while 'doit' is declared to return 'string', it has not
'return' statement. I guess we aren't supposed to care about the
fact that your program as posted doesn't define 'string' or 'cout'
or 'endl'...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 8 '06 #3

Gary Wessle wrote:
Hi

I read an example provided by Big Bucks Inc. no how to use their
library. in it they have some thing like

string doit(){ /* ... */ cout << "doit called" << endl; }

int main(){
doit();
}
how can this be correct?
should not doit() return void? and if not, what am I missing?

thanks
technically, doit() needs to return whatever its return-type is (which
was not shown above). The context in which doit() is called - in this
case: main() - is not obliged in any way to capture the returned value.
The same goes with int main() itself. The operating system is not
required to do anything with its return either.
These returns, if not captured are simply dropped.

Dec 8 '06 #4
Noah Roberts <ro**********@gmail.comwrote:
>It is perfectly ok to ignore a
return value but not to not return a value from a non-void function.
Whatever happened to the days when the last expression evaluated
during a function became the return value, if no "return" was used?

Steve
Dec 9 '06 #5
On Sat, 9 Dec 2006 02:33:27 +0000 (UTC), sp*****@speedymail.org (Steve
Pope) wrote in comp.lang.c++:
Noah Roberts <ro**********@gmail.comwrote:
It is perfectly ok to ignore a
return value but not to not return a value from a non-void function.

Whatever happened to the days when the last expression evaluated
during a function became the return value, if no "return" was used?
That was never part of the C or C++ language. Even in the days of
implicit int in C, when unprototyped functions were assumed to return
an int, what do you think would happen if the last expression
evaluated during a function yielded a floating point type?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Dec 9 '06 #6
Jack Klein <ja*******@spamcop.netwrote:
>On Sat, 9 Dec 2006 02:33:27 +0000 (UTC), sp*****@speedymail.org (Steve
>Whatever happened to the days when the last expression evaluated
during a function became the return value, if no "return" was used?
>That was never part of the C or C++ language. Even in the days of
implicit int in C, when unprototyped functions were assumed to return
an int, what do you think would happen if the last expression
evaluated during a function yielded a floating point type?
What I think probably happened back then was that a particular
register large enough to hold any value that a old-style C function
could return (char, int, long, float, pointer, double -- i.e. a
64 bit register) was loaded with the return value or final expression
value, and then a "return from subroutine" instruction was used.

C had a certain compactness to it but it's
nice to not have to think about low-level stuff anymore.

Steve
Dec 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
1
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it...
1
by: WeCi2i | last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.