473,809 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

two exiting points in void function?

Is there a way to have to exiting point in a void function? I don't want
to exit the program but just this function.

Any answers appreciated.

L. Westmeier

Nov 13 '05 #1
22 6001
In article <bo**********@h ahn.informatik. hu-berlin.de>, L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't want
to exit the program but just this function.

Any answers appreciated.

#include <stdio.h>

void foo(int e)
{
if (e == 0) {
return;
}

printf("didn't exit early, e == %d\n", e);
}
--
Andreas Kähäri
Nov 13 '05 #2
L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't want
to exit the program but just this function.


Use return;

Nov 13 '05 #3
Grumble wrote:
L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't
want to exit the program but just this function.

Use return;

thanks for the fast reply :-)

Nov 13 '05 #4


L. Westmeier wrote:
Grumble wrote:
L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't
want to exit the program but just this function.


Use return;

thanks for the fast reply :-)


Its good practice to only have one return point from a function. Since
you didn't know about "return;", I'm guessing you're new to C so you may
want to post a small, compilable code sample to get feedback on whether
or not you're approaching this the right way.

Ed.

Nov 13 '05 #5
In article <bp********@net news.proxy.luce nt.com>,
Ed Morton <mo************ ****@lucent.com > wrote:
Its good practice to only have one return point from a function.


Its bad practice to only have one return point from a function as the
single return far too often results in a plurality of status flags and
nested if-statements, all needed to go from the wanted return point to
the mandated return point.

--
Göran Larsson http://www.mitt-eget.com/
Nov 13 '05 #6
On Thu, 13 Nov 2003 15:21:34 GMT, ho*@invalid.inv alid (Goran Larsson)
wrote:
In article <bp********@net news.proxy.luce nt.com>,
Ed Morton <mo************ ****@lucent.com > wrote:
Its good practice to only have one return point from a function.


Its bad practice to only have one return point from a function as the
single return far too often results in a plurality of status flags and
nested if-statements, all needed to go from the wanted return point to
the mandated return point.


"Go To Considered Helpful"

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #7
In article <h1************ *************** *****@4ax.com>,
Alan Balmer <al******@spamc op.net> wrote:
"Go To Considered Helpful"


Rules demanding "no goto" are often found where rules demanding
"only one return point" are found. These rules leads to the plurality
of status flags and nested if-statements, often combined with a
nice selection of bugs.

--
Göran Larsson http://www.mitt-eget.com/
Nov 13 '05 #8
On Thu, 13 Nov 2003 12:30:48 +0000 (UTC), Andreas Kahari
<ak*******@free shell.org> wrote:

In article <bo**********@h ahn.informatik. hu-berlin.de>, L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't want
to exit the program but just this function.

Any answers appreciated.

#include <stdio.h>

void foo(int e)
{
if (e == 0) {
return;
}

printf("didn't exit early, e == %d\n", e);
}


#include <stdio.h>

void foo(int e)
{
if (e != 0)
printf("didn't exit early, e == %d\n", e);
}

Same result, single return point.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 13 '05 #9
In article <1e************ *************** *****@4ax.com>, Kevin D Quitt wrote:
In article <bo**********@h ahn.informatik. hu-berlin.de>, L. Westmeier wrote:
Is there a way to have to exiting point in a void function? I don't want
to exit the program but just this function.
[cut] void foo(int e)
{
if (e != 0)
printf("didn't exit early, e == %d\n", e);
}

Same result, single return point.

Not very useful for demonstrating the possibility of multiple
exit points though...

--
Andreas Kähäri
Nov 13 '05 #10

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

Similar topics

6
1608
by: James.D | last post by:
Hi, I met such a problem: //--------------------- // .h class CA { protected: void (CA::*)m_pfn(); public:
5
1626
by: Tim Clacy | last post by:
When exiting function scope, which occurs first: a) destruction of local objects b) copy of value for return From disassembly of a debug target, it looks like the return value is copied before local objects are destroyed. Is this standard behaviour? Can the same behaviour be expected for any optimisation level? As an example, in the function 'int A::fn()' here, is 'b' destroyed before 'i' is copied or vice-versa?:
7
2086
by: akarl | last post by:
Hi all, Why do I get a warning from gcc with the following program? $ cat test.c #include <stdio.h> int f(int n) { return n;
1
2214
by: Karl O. Pinc | last post by:
FYI, mostly. But I do have questions as to how to write code that will continue to work in subsequent postgresql versions. See code below. begintest() uses EXIT to exit a BEGIN block from within nested loops. No problem. begintest2() simplifies this, omitting the nested loops. Still no problem.
23
5720
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() { : : do stuff
7
1202
by: Pietro Cerutti | last post by:
Hi group. I have a problem in a program structured like this: void function_1(my_data_t *data); my_data_t *create_data(void); void library_function(void); int main(void) { my_data_t *data;
6
1880
by: jacek.dziedzic | last post by:
Hello! I have some legacy C code which expects a pointer to a function to be evaluated at one point. Because of the pointer-to-function vs. pointer-to-member incompatibility, this needs to be a global function. To aid the passing of some extra data to the function, it takes an extra parameter of type void* which is passed uninterpreted to it.
4
1251
by: Spiros Bousbouras | last post by:
Assume you have a library which contains the functions foo1, ... , foon which the outside world knows about and may call and the functions bar1, ... , barm which the outside world doesn't know about. The library code does not call anywhere the foo functions but any of the foo or bar functions may call any bar function. So let's say that a bar function (or it could be one of the foo functions) detects an error serious enough that...
1
4068
by: tiffrobe | last post by:
I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. #include <cmath> #include <string> #include <iostream> #include <fstream> #include <cstdlib> using namespace std;
0
9722
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
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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...
1
4333
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
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.