Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Set the result of void function Date: Tue, 19 Sep 2017 19:36:23 -0700 Organization: None to speak of Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="05c0dcee85272ac0f34c4c9724250fb6"; logging-data="32622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nyuGTEj26RsESYe9GngH/" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:CdA6FcKwwpE7zVDeSFVMKqPQ1KA= sha1:DueSO97d8lXOcJfGDBAVy3iD48Y= Xref: csiph.com comp.lang.c:120081 Thiago Adams writes: > Can I set the result of some void function and get it back? A void function doesn't have a result. You can pass information out of it in a number of other ways. [...] > I can do the opposite that is not set the result: > > int F() > { > goto END; > if (0) > return 1; > END:; > } > > int main() > { > int i = F(); > } N1570 6.9.1p12: If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined. There's no need for the goto statement in your example. This: int F(void) { } does the same thing. (The reason it's not a constraint violation is that in pre-ANSI C, void didn't exist, and a function not intended to return a value would be defined with a return type of int. It was up to the caller to avoid using the meaningless result.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"