Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: return type...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 13 Topic 1059 of 1126
Post > Topic >>

Re: return types with conditional

by Jack Klein <jackklein@[EMAIL PROTECTED] > Mar 17, 2008 at 03:21 PM

On Sat, 8 Mar 2008 12:21:45 -0600 (CST), Allan Adler
<ara@[EMAIL PROTECTED]
> wrote in comp.lang.c.moderated:

> Suppose the program is:

I wish you would format your code better.

> main() { fn1(); if (debug == 0) fn2();}

This program uses implicit int for the declaration of main, as you
noted, and is a constraint violation under the 1999 and later versions
of the C standard.

> where fn2() returns int and fn1() returns int*. Since main is implicitly
> being declared as returning int, is there a possible problem here? If
> debug does equal 0, then the last thing to execute is fn2, which returns
> the expected int. If debug does not equal 0, then the last thing to
execute
> is fn1() which returns an unexpected int*.

It would have been much better if you had just typed prototypes of
fn1() and fn2() above main(), instead of describing them in words in
the text.

But I don't understand what you are asking.

There is no return statement in main(), which as you noted is
implicitly defined to return an int.  That means execution "falls off
the end" of main(), unless fn1() or fn2() call exit() and don't
return.

It makes no difference whether main() calls a function that returns
int, or a function that returns something else, before it falls off
the end.  If there is no return statement in main(), than main() does
not return a value, and that means that the exit status returned to
the environment is undefined.

> I am describing a simplification of a piece of code I am reading by
someone
> else.

You seem to think that somehow calling a function returning an int
returns that int value from a containing function, if that is the last
thing the containing function does before hitting its closing brace.

There might be a few compilers that happen to appear to work that way,
perhaps with a specific set of compile-time options.  But if so, that
is merely an accident of the code generation that compiler uses for a
specific processor, and is not something standardized by the C
language.

As far as C is concerned, if main(), implicitly or explicitly defined
to return int, ends at its terminating } without executing a return
statement with a value, the exit status returned to the host
environment is undefined.  Regardless of what main() does before
hitting the closing brace.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.para****ft.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 13 Posts in Topic:
return types with conditional
Allan Adler <ara@[EMAI  2008-03-08 12:21:45 
Re: return types with conditional
Keith Thompson <kst-u@  2008-03-17 15:19:07 
Re: return types with conditional
gordonb.v71k9@[EMAIL PROT  2008-03-17 15:19:10 
Re: return types with conditional
=?ISO-8859-1?Q?Hans-Bernh  2008-03-17 15:20:17 
Re: return types with conditional
Jonathan Leffler <jlef  2008-03-17 15:21:09 
Re: return types with conditional
Thomas Richter <thor@[  2008-03-17 15:21:37 
Re: return types with conditional
Francis Glassborow <fr  2008-03-17 15:21:46 
Re: return types with conditional
Jack Klein <jackklein@  2008-03-17 15:21:48 
Re: return types with conditional
Barry Schwarz <schwarz  2008-03-17 15:21:55 
Re: return types with conditional
Andre Poenitz <poenitz  2008-03-17 15:22:28 
Re: return types with conditional
Keith Thompson <kst-u@  2008-03-20 01:09:19 
Re: return types with conditional
Allan Adler <ara@[EMAI  2008-03-20 01:09:46 
Re: return types with conditional
Kenneth Brody <kenbrod  2008-03-20 15:57:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 1:06:13 CDT 2008.