473,898 Members | 2,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return values for void functions

REH
The other day I did something like this:

void foo
{
}

void bar()
{
return foo();
}

when I meant to do this:

void foo
{
}

void bar()
{
foo();
return;
}

I was suprised that it worked. Is this legal?

Thanks.

Jul 23 '05
23 1949
In message <ct**********@n ntp1.jpl.nasa.g ov>, E. Robert Tisdale
<E.************ **@jpl.nasa.gov > writes
Some guy wrote:
E. Robert Tisdale wrote:
The compiler is a *much* more reliable judge of legal C++ code
than "some guy" who subscribes to the comp.lang.c++ newsgroup. I think that's a pretty bad assessment.
How can someone know if their compiler is any good (compliant)
if they don't themselves know what should be correct?


First of all, there are *no* C++ compiler which comply fully
with the ANSI/ISO standards.


Which rules out *your* suggestion above that the compiler is an
appropriate tool to test compliance.
The Comeau compilers come very close.
It is practically impossible for programmers to determine
for themselves whether any implementation complies or not.
In many cases, not all, it's trivial. Give it some test code, see
whether it compiles and how the compiled code behaves.

But you've digressed. The original question was about whether a piece of
*code* complied with the standard, not some compiler. Other posters
answered the question, complete with citations of the relevant portion
of the standard. If you don't trust them, you can read the standard for
yourself.
This newsgroup has some folks who are pretty darn good at
interpretin g the standard doc's
And many more who are not.
How to you tell the difference.


By reading their reasoned arguments? By reading the standard for
yourself? The question here was straightforward enough, and so directly
answered by the standard, that questions of "interpretation " just didn't
arise.
and presenting the OP with good responses. Who would you trust, your
VC++ 6.0 compiler, or one of the regulars here?


I *don't* trust the "regulars here".


Good advice, since you're one of them.
The comp.lang.c++ newsgroup is *not* the most appropriate forum
to discuss the ANSI/ISO C++ standards or whether or not
any particular implementation complies.
The comp.std.c++ newsgroup is more appropriate.
comp.std.c++ is the appropriate place for discussing the standard and
proposed changes to it. It's not necessarily the best place for
discussing compliance of some random compiler, still less some random
snippet of code.
The comp.std.c++ newsgroup attracts real experts
on the ANSI/ISO C++ standards so contributions
are more likely to be properly vetted.
Contributions making assertions about the standard, certainly.
I'd listen to the regulars (and the FAQ), myself.


That's probably bad advice. The first problem is that
we have no way to determine who the "regulars" are
much less whether or not they have any credentials,
training or experience in C++ compiler implementation.


And how is that any different for the "regulars" of comp.std.c++?

Some of the "regulars" here make testable claims. Some of them have
names and reputations outside this newsgroup. Some of them *are* the
"real experts" you think inhabit comp.std.c++.
We have no way to determine whether their interpretations
of the ANSI/ISO standards are correct or not.


We can read the standard for ourselves and follow their reasoned
arguments, can't we?

--
Richard Herring
Jul 23 '05 #11
msalters wrote:

[ ... ]
Of course, the clc++m group attracts real experts as well. Reason
is simple, moderation keeps the traffic low enough. In fact, such
a trivial question would fit better here or in clc++m than in csc++


clc++/clc++m have similar aims: discussion of the language as it stands
right now. csc++ has a completely different aim: to discuss the
standard for the language, how it should be changed, etc.

The difference here is not one of the level of expertise, but of
orientation. Most of the regulars in csc++ also participate on a
regular basis in clc++ and/or clc++m as well.
That's probably bad advice. The first problem is that
we have no way to determine who the "regulars" are
much less whether or not they have any credentials,
training or experience in C++ compiler implementation.
Google makes it easy to find regulars, but posting and dependability
are (unfortunately) more or less orthogonal.

Standard conformance is largely a question of facts (or lack thereof),
and is thus easier to evaluate on its own merits. The place you really
want to look for expertise is when somebody is giving advice about
programming technique. Here you're (largely) taking a guess at what's
likely to become useful in the future, so you're hoping that the
expert's experience will guide you into making decisions that turn out
well -- but knowing up front that no matter what you do, you're
basically playing the odds, with no facts about "right" or "wrong"
available until after the fact.

Even so, I, at least, believe that your judgement should be based more
on the qualities apparent in the arguments themselves than in the
reputation of the person who makes them. Just for one example, I can
remember the first few posts Andrei Alexandrescu made to comp.lang.c++:
he had virtually never posted anything, anywhere before, and I'd
certainly never heard of him before (this was well before he was
published). Dismissing him out of hand on that basis would have been a
_major_ mistake, at least IMO.
We have no way to determine whether their interpretations
of the ANSI/ISO standards are correct or not.


You don't have to implement a compiler to know one is wrong.
In fact, once you gain some experience, you'll learn what's
easy and what's impossible without implementing one. And
for 99% of the questions here, any interpretation backed by
a quote is correct simply because there is no misinterpretati on
possible. The "expert" part is finding the right quote.


I'm not at all sure I'd agree with the 99% number, but there are
certainly quite a few questions for which the answers are sufficiently
well known that one quote from the correct part of the standrad
suffices as an answer.

A single quote will rarely suffice for an expert-level question though.
A difficult question might easily require bits and pieces from a half
dozen (often widely-separated) parts of the standard to resolve.

Worse, the standard is sufficiently large that when those half dozen
parts are combined, the result can be _most_ surprising to those who
think they know the standard the best (it certainly suprises me on a
regular basis).

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #12
REH

"Howard" <al*****@hotmai l.com> wrote in message
news:3t******** *********@bgtns c04-news.ops.worldn et.att.net...

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:ct******** **@nntp1.jpl.na sa.gov...
REH wrote:
The compiler is a *much* more reliable judge of legal C++ code
than "some guy" who subscribes to the comp.lang.c++ newsgroup.
I think that's a pretty bad assessment. How can someone know if their
compiler is any good (compliant), if they don't themselves know what

should be correct? This newsgroup has some folks who are pretty darn good at
interpreting the standard doc's and presenting the OP with good responses.
Who would you trust, your VC++ 6.0 compiler, or one of the regulars here?
I'd listen to the regulars (and the FAQ), myself.

-some guy

That's quoted wrong. He wrote that crap, not me!

REH


Jul 23 '05 #13
REH

"Greg Comeau" <co****@panix.c om> wrote in message
news:ct******** **@panix1.panix .com...
In article <ct*********@cu i1.lmms.lmco.co m>, REH <bo***@nowhere. net> wrote:
The other day I did something like this:

void foo
{
}

void bar()
{
return foo();
}

when I meant to do this:

void foo
{
}

void bar()
{
foo();
return;
}

I was suprised that it worked. Is this legal?


Notwithstanding that your foo above is defined incorrectly,


Yes, sorry, I was just trying too quickly to sketch an example of what I
wrote.
As you mentioned, despite the legality, it may not necessarily
be what you wanted, or it may be (this becomes more transparent
with templates).

Other than clarity or style/preferences (or the surprise!), is there a
reason why it's not what I wanted? I assume, from what I've been told, is
it's the same (functionally) as what I did want.

Thanks.
Jul 23 '05 #14

"REH" <bo***@nowhere. net> wrote in message
news:ct******** *@cui1.lmms.lmc o.com...

"Howard" <al*****@hotmai l.com> wrote in message
news:3t******** *********@bgtns c04-news.ops.worldn et.att.net...

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:ct******** **@nntp1.jpl.na sa.gov...
> REH wrote:
>
>
> The compiler is a *much* more reliable judge of legal C++ code
> than "some guy" who subscribes to the comp.lang.c++ newsgroup.
....

That's quoted wrong. He wrote that crap, not me!

REH


Sorry, I forgot to take out the line with "REH wrote:" when I snipped all
the stuff at the top.

-H
Jul 23 '05 #15
Richard Herring wrote:
E. Robert Tisdale writes:
We have no way to determine whether their interpretations
of the ANSI/ISO standards are correct or not.


We can read the standard for ourselves
and follow their reasoned arguments, can't we?


And, if we are ourselves infallible,
we can determine whether their interpretations
of the ANSI/ISO standards are correct or not.

According to the American Heritage Dictionary of the English Language

http://www.bartleby.com/61/

hubris
NOUN: Overbearing pride or presumption; arrogance:
“There is no safety in unlimited technological hubris”
(McGeorge Bundy).
I have observed that, when the same question is submitted
to both comp.lang.c++ and comp.std.c++ independently,
answers are challenged much more vigorously in comp.std.c++
The answers and challenges are much better and more reliable
in comp.std.c++
It appears that more experts on the ANSI/ISO C++ standards
subscribe and contribute to the comp.std.c++ newsgroup.

What I find most interesting is that many so-called experts
pronounced the original code snippet

void foo
{
}

void bar()
{
return foo();
}

submitted by REH "legal".
Evidently, none of them ever attempted to compile it.
In this case, *any* C++ compiler would have been
more reliable that the so-called experts.

If you have questions about whether a code is "legal" or not,
consult your C++ compiler first.
Consult the Comeau on-line C++ compiler
if you don't trust your compiler.
Consult the experts in the comp.std.c++ newsgroups
if doubt or suspicion remains.
The comp.lang.c++ newsgroup is just a good place to get bad advice
on "legal" issues concerning ANSI/ISO C++ standards.
Jul 23 '05 #16
REH

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:ct******** **@nntp1.jpl.na sa.gov...
What I find most interesting is that many so-called experts
pronounced the original code snippet

void foo
{
}

void bar()
{
return foo();
}

submitted by REH "legal".
Evidently, none of them ever attempted to compile it.
In this case, *any* C++ compiler would have been
more reliable that the so-called experts.

I don't think they pronounced it legal or felt the need to compile it.
They, being smarter than a compiler, understand my mistake and intent, and
just answered my question. Sheesh, it was just an example to help convey
what I was trying to say.
Jul 23 '05 #17
REH wrote:
E. Robert Tisdale wrote:
What I find most interesting is that many so-called experts
pronounced the original code snippet

void foo
{
}

void bar()
{
return foo();
}

submitted by REH "legal".
Evidently, none of them ever attempted to compile it.
In this case, *any* C++ compiler would have been
more reliable that the so-called experts.


I don't think they pronounced it legal or felt the need to compile it.
They, being smarter than a compiler, understand my mistake and intent
and just answered my question.
Sheesh, it was just an example to help convey what I was trying to say.


Someday, we will have compilers that are that smart. ;-)
They will emit code code for the program that we should have written
instead of for the program that we actually wrote.
What will we need programmers for then?
Jul 23 '05 #18

E. Robert Tisdale wrote:
Some guy wrote:
E. Robert Tisdale wrote:
The compiler is a *much* more reliable judge of legal C++ code
than "some guy" who subscribes to the comp.lang.c++ newsgroup.


I think that's a pretty bad assessment.
How can someone know if their compiler is any good (compliant)
if they don't themselves know what should be correct?


First of all, there are *no* C++ compiler which comply fully
with the ANSI/ISO standards.


Ok, then I have a question. If there are no compliant C++
compilers,...wh y would I trust one to judge if my code is compliant?!
I'm confused.

Jul 23 '05 #19
Noah Roberts wrote:
E. Robert Tisdale wrote:
Some guy wrote:
E. Robert Tisdale wrote:

The compiler is a *much* more reliable judge of legal C++ code
than "some guy" who subscribes to the comp.lang.c++ newsgroup.

I think that's a pretty bad assessment.
How can someone know if their compiler is any good (compliant)
if they don't themselves know what should be correct?
First of all, there are *no* C++ compiler
which comply fully with the ANSI/ISO standards.

Ok, then I have a question.
If there are no compliant C++ compilers,
why would I trust one to judge if my code is compliant?


Because they are *more* reliable (trustworthy)
than contributers to the comp.lang.c++ newsgroup.
Compilers are written by professionals
who are much more expert in interpreting
the ANSI/ISO C++ standards
than the casual, pedestrian users
who contribute to the comp.lang.c++ newsgroup.
I'm confused.

Jul 23 '05 #20

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

Similar topics

66
5057
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
9
2736
by: Ann Huxtable | last post by:
I have the following code segment - which compiles fine. I'm just worried I may get run time probs - because it looks like the functions are being overloaded by the return types?. Is this Ok: ? template <class T1, class T2> int getValue( T1 col, T2 row ) ; template <class T1, class T2> double getValue( T1 col, T2 row ) ;
16
2013
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't see how the return value comes to play here. Ex
15
2820
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
18
2466
by: skishorev | last post by:
Hi, Here I am taking two functions. void f(int,int) and another one is float f(int,int). Is it possible to overload with return values. Thx, kishore
4
6960
by: msolem | last post by:
I have some code where there are a set of functions that return pointers to each other. I'm having a bit of a hard time figuring out the correct type to use to do that. The code below works but I'm defining the functions as void*, and then casting when I use them. This code is going into a general purpose framework, and it would be much nicer if the user didn't need to do any casting. Can someone tell me how to set up those typedefs...
18
4078
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
2
4544
by: rsk | last post by:
Friends, The following logic just converts the hexadecimal values to the binay values taken into the array. for(i=31;i>=0;i--){ if ((1<<i)&var1) array_var1=1; else array_var1=0;
4
2491
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. Here's the approach I'm currently looking at. I throw exceptions only from constructors. Destructors, of course, do not throw exceptions. All other functions return a signed integer. The values are all stored in one large header file (as...
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9840
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10483
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4706
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3305
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.