Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #120068 > unrolled thread
| Started by | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| First post | 2017-09-19 14:23 -0700 |
| Last post | 2017-09-20 15:30 -0700 |
| Articles | 20 on this page of 183 — 28 participants |
Back to article view | Back to comp.lang.c
Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-19 14:23 -0700
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-19 14:38 -0700
Re: Set the result of void function gordonb.tfand@burditt.org (Gordon Burditt) - 2017-09-19 17:16 -0500
Re: Set the result of void function "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-09-20 00:39 +0200
Re: Set the result of void function James Kuyper <jameskuyper@verizon.net> - 2017-09-19 22:06 -0400
Re: Set the result of void function "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-09-20 06:51 +0200
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-20 10:55 +0100
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-20 12:11 +0100
Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 07:17 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-20 11:28 +0100
Re: Set the result of void function mark.bluemel@gmail.com - 2017-09-20 03:30 -0700
Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 06:53 -0700
Re: Set the result of void function Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-09-21 03:50 -0500
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-21 11:00 +0100
Re: Set the result of void function scott@slp53.sl.home (Scott Lurndal) - 2017-09-21 12:39 +0000
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-21 14:12 +0100
Re: Set the result of void function scott@slp53.sl.home (Scott Lurndal) - 2017-09-21 13:51 +0000
Re: Set the result of void function Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-09-21 08:36 -0600
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-21 17:51 +0100
Re: Set the result of void function supercat@casperkitty.com - 2017-09-21 10:06 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 08:51 +0200
Plunging innocent people into poverty (Was: Set the result of void function) gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-23 09:31 +0000
Re: Plunging innocent people into poverty (Was: Set the result of void function) David Brown <david.brown@hesbynett.no> - 2017-09-23 12:09 +0200
Re: Plunging innocent people into poverty (Was: Set the result of void function) gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-23 10:25 +0000
Re: Plunging innocent people into poverty Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-09-23 10:43 -0600
Re: Plunging innocent people into poverty supercat@casperkitty.com - 2017-09-23 10:41 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 09:37 +0200
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-22 11:27 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 14:42 +0200
Re: Set the result of void function Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-09-24 12:09 +0000
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 08:31 +0200
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 03:52 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 13:25 +0200
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 04:58 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 14:20 +0200
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 13:44 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 15:09 +0200
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 05:44 -0700
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 05:58 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 15:15 +0200
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 06:46 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 16:01 +0200
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 07:18 -0700
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 07:55 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 08:49 -0700
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 09:21 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-25 09:51 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 21:57 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 15:03 -0700
Re: Set the result of void function Öö Tiib <ootiib@hot.ee> - 2017-09-25 21:34 -0700
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-26 04:28 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-27 08:26 +0200
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-27 11:48 -0400
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 08:54 +0200
Re: Set the result of void function gordonb.iddsu@burditt.org (Gordon Burditt) - 2017-09-28 23:33 -0500
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 09:15 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 17:50 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 10:35 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-27 18:47 +0100
Re: Set the result of void function supercat@casperkitty.com - 2017-09-27 10:52 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 11:10 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:10 +0200
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 11:06 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 20:01 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 12:26 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 20:38 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 13:00 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 21:54 +0100
Re: Set the result of void function supercat@casperkitty.com - 2017-09-27 14:12 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 14:34 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 23:16 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 16:09 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 01:12 +0100
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 02:03 +0100
Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-28 17:31 +1300
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:55 +0200
Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-28 21:00 +1300
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 10:48 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 13:20 +0200
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 11:29 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 20:27 -0700
Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:30 +0100
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-29 19:45 +0100
Re: Set the result of void function Jerry Stuckle <jstucklex@attglobal.net> - 2017-09-29 14:49 -0400
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 15:07 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:42 +0200
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 13:55 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 17:22 +0200
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:14 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 20:13 +0200
Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:42 +0100
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-28 09:14 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:25 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 20:17 +0200
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 17:39 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 10:10 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 19:05 +0100
Re: Set the result of void function "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-09-28 14:20 -0400
Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-29 07:52 +1300
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 11:59 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 18:50 +0100
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 19:47 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 21:57 +0200
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 16:14 -0400
Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 13:17 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 21:23 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 13:55 -0700
Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:50 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 13:57 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 23:18 +0200
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 17:38 -0400
Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 15:54 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-29 08:59 +0200
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:43 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-29 10:43 +0200
Re: Set the result of void function supercat@casperkitty.com - 2017-09-29 07:43 -0700
Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-30 19:21 +0100
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-30 19:45 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 13:31 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 13:41 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:07 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 16:25 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 18:45 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 19:54 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 20:51 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 22:39 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 09:16 -0700
Re: Set the result of void function gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-29 16:17 +0000
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 11:05 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 11:23 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-29 12:15 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:04 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 16:44 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-30 10:04 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-30 10:33 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 11:26 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:03 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 09:44 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 11:15 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 11:35 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:11 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:14 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-30 08:55 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 11:36 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 12:05 +0100
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 12:17 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 09:15 -0700
Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-29 09:42 +1300
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 21:55 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:12 -0700
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 17:22 -0400
Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:50 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:00 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 09:35 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 10:57 -0700
Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 10:35 -0700
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 06:57 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 16:32 +0100
Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 08:43 -0700
Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 22:12 +0100
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 09:03 -0700
Re: Set the result of void function Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-09-25 14:17 +0000
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-20 11:32 -0400
Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 01:50 -0700
Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-20 15:56 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-19 23:01 +0100
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-20 15:40 +0200
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-20 08:50 -0700
Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-20 22:52 +0200
Re: Set the result of void function supercat@casperkitty.com - 2017-09-20 15:04 -0700
Re: Set the result of void function supercat@casperkitty.com - 2017-09-20 07:39 -0700
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-19 15:18 -0700
Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-20 01:21 +0100
Re: Set the result of void function jameskuyper@verizon.net - 2017-09-19 19:40 -0700
Re: Set the result of void function rockbrentwood@gmail.com - 2017-09-19 16:36 -0700
Re: Set the result of void function James Kuyper <jameskuyper@verizon.net> - 2017-09-19 22:13 -0400
Re: Set the result of void function gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-22 01:48 +0000
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-19 19:36 -0700
Re: Set the result of void function mark.bluemel@gmail.com - 2017-09-20 01:00 -0700
Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 02:01 -0700
Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-20 08:36 -0700
Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-20 11:36 -0400
Re: Set the result of void function John Bode <jfbode1029@gmail.com> - 2017-09-20 15:30 -0700
Page 9 of 10 — ← Prev page 1 … 7 8 [9] 10 Next page →
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2017-09-25 09:03 -0700 |
| Message-ID | <lning622ah.fsf@kst-u.example.com> |
| In reply to | #120302 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
>> The C way of writing a swap is
>>
>> void memswap(void *ptra, void *ptrb, size_t length);
>
> In modern C
>
> void memswap(void *restrict ptra, void *restrict ptrb, size_t length);
>
> might be better. Writing it this way makes it clear that the code is
> intended to be used to swap the contents of non-overlapping objects.
Sure, *if* you want to impose that restriction. On the other hand, you
might prefer a function that can handle swapping an object with itself.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2017-09-25 14:17 +0000 |
| Message-ID | <slrnosi3us.14au.grahn+nntp@frailea.sa.invalid> |
| In reply to | #120270 |
On Mon, 2017-09-25, David Brown wrote: > On 24/09/17 14:09, Jorgen Grahn wrote: >> On Fri, 2017-09-22, David Brown wrote: >>> On 22/09/17 12:27, bartc wrote: >> ... >>>> Here's a real example from my code (not C, and part of a rotate routine): >>>> >>>> swap(a[first++],a[nxt++]) >>> >>> If someone showed me that for a code review, I'd be merciful the first >>> time - I'd only shot the code. >>> >>> Honestly, I really do not /care/ what a language might do here, because >>> the source is unclear. Don't write code that depends on the order of >>> side effects, or that will be different if what looks like a function >>> call happens to be a macro, or a language extension. >> >> I haven't paid attention to this thread (I have no interest at all in >> bartc's language, and so on) but if it was C++ and >> >> std::swap(a[p++], a[q++]) >> >> I don't find that unclear at all, and the side effects are well under >> control. >> > > In C++, you know std::swap is not a macro. As long as you are not doing > something programmer-unfriendly, like defining [] or ++ operators that > act in unexpected ways, then the ordering and effects is clear. > > In C, this sort of thing tends to be a macro. The operands to "swap" > might be evaluated several times in different orders - or they might be > handled in a safe manner (using compiler extensions like "typeof"). C++ > lets you write a good "swap" function - C does not. Oh, ok. Yes, if we were back in the real, topical, C world, the swap() above would have made me suspicious. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | "James R. Kuyper" <jameskuyper@verizon.net> |
|---|---|
| Date | 2017-09-20 11:32 -0400 |
| Message-ID | <8aa80989-13bc-dc59-9f84-bbc2d99a6059@verizon.net> |
| In reply to | #120084 |
On 2017-09-20 00:51, Pascal J. Bourguignon wrote: > James Kuyper <jameskuyper@verizon.net> writes: > >> On 09/19/2017 06:39 PM, Pascal J. Bourguignon wrote: >> ... >>> In C, functions can only return a simple value; granted, some extension >>> or perhaps in later standards, you can return a structure too, >> >> Every version of the C standard, all the way back to C89, has allowed > > Yes, this is what I call later standards… Well, you shouldn't. Use of the term "later standards" implies that that you're partitioning the versions of the C standard into two groups: the earlier standards, which prohibited returning a struct value, and the later standards, which allowed it. They're called "later standards" because they are later than the "earlier standards" - but those "earlier standards" are an empty set, so the phrase doesn't make any sense. There has been a version of C, K&R C, which did not allow returning a struct value - but that version was not a standard. It could, at best, have been described as an inspiration. People would read Kernighan and Ritchie's "The C Programming Language", and think to themselves "Wow, that's a great idea. I should invent my own language similar to K&R C, but I'll drop the features I don't like, add features I do like, and modify features that I think should have been handled differently. And just for the fun of it, I'm going to call my language C as well". I started programming in C during that era, and portability issues were a nightmare. Anyone who thinks that K&R C served as a "de-facto standard" probably never attempted to write portable code during that era. If you had said "perhaps in later versions of C", that would have have conveyed your intended meaning - but if so, you should have coupled that with starting the sentence by saying "In K&R C,", so the reader would have had a point of reference for determining which versions qualify as "later". That's the only version of C that your sentence accurately describes, and it was rendered obsolete by the publication of C89, nearly three decades ago.
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2017-09-20 01:50 -0700 |
| Message-ID | <97f1f40a-e472-4be1-b836-cbdcd7167d7a@googlegroups.com> |
| In reply to | #120079 |
W dniu środa, 20 września 2017 04:06:32 UTC+2 użytkownik James Kuyper napisał: > On 09/19/2017 06:39 PM, Pascal J. Bourguignon wrote: > ... > > In C, functions can only return a simple value; granted, some extension > > or perhaps in later standards, you can return a structure too, > > Every version of the C standard, all the way back to C89, has allowed > returning a single (aggregate) value of struct type. Any compiler that > doesn't support that is nearly three decades out-of-date. note btw that efficiency of returning values shouldnt in fact be worse than those of passing ones (i mean returning 5 ints sjould equal to passing 5 ints) in pure stack way i think it can be done like this i1, i2, i3 = foo(i4, i5, i6, i7); push i3 push i2 push i1 push i7 push i6 push i5 push i4 call foo add esp, 16 it is also compatible with variadic input push i3 push i2 push i1 push n bytes of whatever you wnat call foo add esp, n it is also compatible in sorta-variadic output i mean such kind of variadic output when caller decides how many bytes get back i1 = foo(frmt); i1,i2 = foo(frmt); i1,i2,i3 = foo(frmt); (i probably would like to get such variadic output in C2 probably it could be usefull as one function would be used as a 'stream' that can give various kind of data) if calle would like to decide it would need to use reserve or additional stack or memory region ( this caller-decide variadic output maybe can be considered a bit more sane BTW as calle-decide variadic outpud would need something like va_start va_arg etc to read output from such function ;c (i would dio it by hand btw - some things still to consider here)
[toc] | [prev] | [next] | [standalone]
| From | David Kleinecke <dkleinecke@gmail.com> |
|---|---|
| Date | 2017-09-20 15:56 -0700 |
| Message-ID | <0bab8204-d29d-4025-b44c-5312424d3bc0@googlegroups.com> |
| In reply to | #120088 |
On Wednesday, September 20, 2017 at 1:50:34 AM UTC-7, fir wrote: > W dniu środa, 20 września 2017 04:06:32 UTC+2 użytkownik James Kuyper napisał: > > On 09/19/2017 06:39 PM, Pascal J. Bourguignon wrote: > > ... > > > In C, functions can only return a simple value; granted, some extension > > > or perhaps in later standards, you can return a structure too, > > > > Every version of the C standard, all the way back to C89, has allowed > > returning a single (aggregate) value of struct type. Any compiler that > > doesn't support that is nearly three decades out-of-date. > > note btw that efficiency of returning values shouldnt in fact be worse than those of passing ones (i mean > returning 5 ints sjould equal to passing 5 ints) > > in pure stack way i think it can be done like this > > i1, i2, i3 = foo(i4, i5, i6, i7); > > push i3 > push i2 > push i1 > push i7 > push i6 > push i5 > push i4 > call foo > add esp, 16 > > > it is also compatible with variadic input > > push i3 > push i2 > push i1 > push n bytes of whatever you wnat > call foo > add esp, n > > it is also compatible in sorta-variadic output > i mean such kind of variadic output when caller > decides how many bytes get back > > i1 = foo(frmt); > i1,i2 = foo(frmt); > i1,i2,i3 = foo(frmt); > > (i probably would like to get such variadic output in C2 > > probably it could be usefull as one function would be used as a 'stream' that can give various kind of data) > > if calle would like to decide it would need to use reserve or additional stack or memory region > > ( this caller-decide variadic output maybe can be considered a bit more sane BTW as calle-decide variadic outpud would need something like va_start va_arg etc to read output from such function ;c > (i would dio it by hand btw > - some things still to consider here) What you are doing here is simply avoiding structs. Why bother?
[toc] | [prev] | [next] | [standalone]
| From | bartc <bc@freeuk.com> |
|---|---|
| Date | 2017-09-19 23:01 +0100 |
| Message-ID | <osgwB.770836$uh.764880@fx28.am4> |
| In reply to | #120068 |
On 19/09/2017 22:23, Thiago Adams wrote:
>
> Can I set the result of some void function and get it back?
>
>
> I ask just to see if I can put some error code in void functions.
>
> Also to understand how everything works under the hood if the
> solution is just for x86 for instance.
>
>
>
>
> ----
>
> I can do the opposite that is not set the result:
>
> int F()
> {
> goto END;
> if (0)
> return 1;
> END:;
> }
You can't really do this. And I can't understand why compilers allow it
(except to be able to compile code that was developed with a compiler
that allowed it. But at some point, enough is enough.).
On x86 hardware for example, the return value of F() is typically passed
in register EAX. And that is ALWAYS expected to contain the return
value, when the return value is used as in i=F().
What value will be in EAX when there is no explicit return statement?
Probably garbage.
With a function returning void, there will never be any value in EAX,
RAX, ST0 or XMM0 (all the places in x86/x86 where a return value of
int/pointer/float might normally be passed).
And no code will exist for using the result of such a function, as the
return value will ostensibly be void, which ought to trigger an error if
trying to do anything that such a value (but I don't trust C compilers
any more to diagnose such blatant errors).
If you want to figure out what a compiler does, look at the ASM output
of a simple C compiler (not gcc), and with no optimisation.
(I can't recommend mine at the minute as it generates very clunky ASM
that nearly as hard to follow as gcc's code. Although the older version
isn't too bad: try compiling and running: www.bcas.freeuk.com/oldmcc.c
For this purpose (perusing the .asm output), I think it compiles and
runs on both Windows and Linux, although the API model used is Windows'.
Build instructions at the start.)
--
bartc
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2017-09-20 15:40 +0200 |
| Message-ID | <optr59$506$1@dont-email.me> |
| In reply to | #120071 |
On 20/09/17 00:01, bartc wrote:
> On 19/09/2017 22:23, Thiago Adams wrote:
>>
>> Can I set the result of some void function and get it back?
>>
>>
>> I ask just to see if I can put some error code in void functions.
>> Also to understand how everything works under the hood if the
>> solution is just for x86 for instance.
>>
>>
>>
>>
>> ----
>>
>> I can do the opposite that is not set the result:
>>
>> int F()
>> {
>> goto END;
>> if (0)
>> return 1;
>> END:;
>> }
>
> You can't really do this. And I can't understand why compilers allow it
> (except to be able to compile code that was developed with a compiler
> that allowed it. But at some point, enough is enough.).
You /can/ really do this - and compilers allow it because the language
allows it, and the language allows it for backwards compatibility.
If you have a non-void function like "int F(void)", then a "return"
without an expression is a constraint violation - compilers are allowed
to guess what you mean by it, or to complain about it. Falling off the
end of a non-void function is allowed, but if you use the result
"returned" then it is undefined behaviour. So you are allowed to write:
double square_root(double x, bool * valid) {
if (x >= 0) {
*valid = true;
return sqrt(x);
}
*valid = false;
}
void print_square_root(double x) {
bool valid;
double y = square_root(y, &valid);
if (valid) {
printf("Square root of %g is %g\n", x, y);
} else {
printf("You are just imagining that %g has a square root\n", x);
}
}
It's a silly way to handle it, IMHO, and compilers will often complain
(at least when the user knows how to enable warnings), but it AFAIK it
is legal C and will work as expected.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2017-09-20 08:50 -0700 |
| Message-ID | <lnk20t5pzk.fsf@kst-u.example.com> |
| In reply to | #120096 |
David Brown <david.brown@hesbynett.no> writes:
[...]
> If you have a non-void function like "int F(void)", then a "return"
> without an expression is a constraint violation - compilers are allowed
> to guess what you mean by it, or to complain about it.
Conforming compilers are allowed (but not required) to guess what you
mean, and are *required* to complain about it. (Good compilers, IMHO,
will reject it with a fatal error message.)
> Falling off the
> end of a non-void function is allowed, but if you use the result
> "returned" then it is undefined behaviour. So you are allowed to write:
>
> double square_root(double x, bool * valid) {
> if (x >= 0) {
> *valid = true;
> return sqrt(x);
> }
> *valid = false;
> }
>
> void print_square_root(double x) {
> bool valid;
> double y = square_root(y, &valid);
> if (valid) {
> printf("Square root of %g is %g\n", x, y);
> } else {
> printf("You are just imagining that %g has a square root\n", x);
> }
> }
I believe the behavior is undefined. The standard says the behavior is
undefined if the value "is used by the caller". It's not 100% clear
what "used" means, but I'd say that the caller uses the result by
storing it in y. (And you meant to pass x, not y, as the first argument
to square_root().)
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2017-09-20 22:52 +0200 |
| Message-ID | <opukdo$m7l$1@dont-email.me> |
| In reply to | #120104 |
On 20/09/17 17:50, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
> [...]
>> If you have a non-void function like "int F(void)", then a "return"
>> without an expression is a constraint violation - compilers are allowed
>> to guess what you mean by it, or to complain about it.
>
> Conforming compilers are allowed (but not required) to guess what you
> mean, and are *required* to complain about it. (Good compilers, IMHO,
> will reject it with a fatal error message.)
Thanks for the correction. (I agree with you about what "good
compilers" should do. gcc needs -Wall or -Wpedantic to complain, and
-Werror to give a fatal error, based on a brief test. I wonder how many
fewer bugs there would be if compilers had the equivalent of "-Wall
-Werror" by default, and required explicit flags to enable code like my
example below to compiler.)
>
>> Falling off the
>> end of a non-void function is allowed, but if you use the result
>> "returned" then it is undefined behaviour. So you are allowed to write:
>>
>> double square_root(double x, bool * valid) {
>> if (x >= 0) {
>> *valid = true;
>> return sqrt(x);
>> }
>> *valid = false;
>> }
>>
>> void print_square_root(double x) {
>> bool valid;
>> double y = square_root(y, &valid);
>> if (valid) {
>> printf("Square root of %g is %g\n", x, y);
>> } else {
>> printf("You are just imagining that %g has a square root\n", x);
>> }
>> }
>
> I believe the behavior is undefined. The standard says the behavior is
> undefined if the value "is used by the caller". It's not 100% clear
> what "used" means, but I'd say that the caller uses the result by
> storing it in y.
I am considering storing it in y, but then not using y, as /not/ using
it in the caller. But I have not found any definition of "used by", so
your interpretation (and therefore conclusion) is at least as valid as mine.
> (And you meant to pass x, not y, as the first argument
> to square_root().)
>
Indeed.
I remember reading somewhere about the benefits of testing code before
publishing it...
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2017-09-20 15:04 -0700 |
| Message-ID | <f565c232-76d8-4b93-97a4-25573f4fd3eb@googlegroups.com> |
| In reply to | #120107 |
On Wednesday, September 20, 2017 at 3:52:26 PM UTC-5, David Brown wrote: > I am considering storing it in y, but then not using y, as /not/ using > it in the caller. But I have not found any definition of "used by", so > your interpretation (and therefore conclusion) is at least as valid as mine. On a few platforms, it might be expensive to ensure that even the mere act of storing a function's code would not have unwanted side-effects in cases where the function fell through without a "return value;" statement. On many other platforms, however, it would cost nothing. Both the cost and value of the guarantee could vary significantly among platforms and application fields. A best-of-both-worlds solution would be to have implementations for platforms that can uphold the guarantee cheaply, do so, and say that code may use the guarantee only if it will never be run on platforms where it might be expensive. That would go against modern philosophy, however.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2017-09-20 07:39 -0700 |
| Message-ID | <d4f2a9b7-a848-4fe5-996c-c18d1758d06a@googlegroups.com> |
| In reply to | #120071 |
On Tuesday, September 19, 2017 at 5:01:06 PM UTC-5, Bart wrote:
> On x86 hardware for example, the return value of F() is typically passed
> in register EAX. And that is ALWAYS expected to contain the return
> value, when the return value is used as in i=F().
>
> What value will be in EAX when there is no explicit return statement?
> Probably garbage.
>
> With a function returning void, there will never be any value in EAX,
> RAX, ST0 or XMM0 (all the places in x86/x86 where a return value of
> int/pointer/float might normally be passed).
On x86 hardware, there is *always* a value in EAX/RAX/etc. The value will
not generally be meaningful if a function exits via other than by a
"return value;" statement, but there will be a value there. If one has
a function with a "mode" parameter where some modes are required to yield
meaningful numbers, and callers who supply other modes should not expect
to receive a meaningful or consistent value, it is perfectly legitimate
(though discouraged) to have such a function use "return value;" when used
with modes that return values, and to have it fall through with modes that
don't. Doing this will sometimes allow the "no-value" cases to be slightly
more efficient than if they had to return a particular value.
For example:
uint16_t actUponPtr(int mode, uint16_t volatile *p, uint16_t param)
{
if (mode == 0) return *p;
*p = param;
}
If there were a standard form of "return an arbitrary value", that could
be a clearer (and in pretty much every way better) way of letting the
compiler omit code to set the return value, but there is no standard syntax
for that.
If an implementation for a typical CPU processes code for different functions
separately, it will be possible to write a wrapper for a function that may or
may not return a meaningful value and return the value to the caller in cases
when it is meaningful, without the wrapper having to worry about the cases
where the function doesn't "return a value", e.g.
uint16_t useRemotePtr(
uint16_t (*action)(int, uint16_t volatile*, uint16_t),
int mode, uint16_t volatile*p, uint16_t param)
{
uint16_t ret;
enable_remote_memory();
ret=action(mode, p, param);
disable_remote_memory();
return ret;
}
without having to worry about whether "action" returns a meaningful value.
On something like the ARM, it's entirely possible that if action() does
falls through rather than using "return n", the value in "ret" might not
be in the range 0-65535, but if whatever is calling "useRemotePtr" does
not use the return value (except possible to pass it further up the call
stack) that shouldn't matter.
If one has control over the functions that are going to be called via
wrapper like the above, it's probably better to have them return defined
values in all cases than to have them sometimes perform a "fall-through
return". If one needs to link with an external library that sometimes
does fall-through returns, however, having a compiler be agnostic to
whether or not (*action)() returns a value may be nicer than having to
write the wrapper function as:
uint16_t useRemotePtr(
uint16_t (*action)(int, uint16_t volatile*, uint16_t),
int mode, uint16_t volatile*p, uint16_t param)
{
uint16_t ret;
enable_remote_memory();
if (mode==0)
ret=action(mode, p, param);
else
{
ret=0;
action(mode, p, param);
}
disable_remote_memory();
return ret;
}
Incidentally, this ties in with a similar ability older implementations
used to offer when calling functions: given
unsigned short useRemotePtr(action, mode, p, param)
{
unsigned short (*action)();
int mode;
unsigned short *p;
unsigned short param;
{
uint16_t ret;
enable_remote_memory();
ret=action(mode, p, param);
disable_remote_memory();
return ret;
}
a caller could save a little code by omitting "param" when mode was 0. Bad
things could and likely would happen if a called function wrote to a
parameter for which no argument had been passed, but everything else would
work as necessary. Even on platforms where the normal calling convention
would die if functions were passed fewer arguments than expected, C
implementations often used a different convention. Here again, the "right"
approach would be to have a standard syntax for arguments the called
function isn't going to use, but no such thing exists.
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@verizon.net |
|---|---|
| Date | 2017-09-19 15:18 -0700 |
| Message-ID | <057c5537-0e6b-485a-b006-f7a5d40d209f@googlegroups.com> |
| In reply to | #120068 |
On Tuesday, September 19, 2017 at 5:24:04 PM UTC-4, Thiago Adams wrote:
> Can I set the result of some void function and get it back?
That's a constraint violation: "A return statement with an expression shall not
appear in a function whose return type is void." (6.8.6.4p1)
> I ask just to see if I can put some error code in void functions.
>
> Also to understand how everything works under the hood if the
> solution is just for x86 for instance.
>
>
>
>
> ----
>
> I can do the opposite that is not set the result:
>
> int F()
> {
> goto END;
> if (0)
> return 1;
> END:;
This function is completely pointless as written. I suspect that you intended
that some or all of the features that make it pointless would be subject to
removal under some circumstance. If so, it would be cleared to demonstrate the
removal explicitly:
#ifdef RETURN
return 1;
#endif
> }
>
> int main()
> {
> int i = F();
> }
This has undefined behavior: "If the } that terminates a function is reached,
and the value of the function call is used by the caller, the behavior is
undefined." (6.9.1p12)
Using my RETURN-based example, you could do the following:
#ifdef RETURN
int i =
#endif
F();
Would something like that suit your needs? You can also switch at runtime:
void F(_Bool return)
{
if(return)
return 1;
}
int main(int argc, char *argv[])
{
int result = 0;
if(argc>2)
result = F(argc>2);
else
F(argc>2);
}
This is a dangerous technique, since it's entirely your responsibility to make
sure that the returned value is used only if a value is returned - the compiler
does not, in general, have enough information to help you with that. However, it
is permitted by 6.9.1p12.
[toc] | [prev] | [next] | [standalone]
| From | bartc <bc@freeuk.com> |
|---|---|
| Date | 2017-09-20 01:21 +0100 |
| Message-ID | <gwiwB.1012069$tN5.22252@fx27.am4> |
| In reply to | #120073 |
On 19/09/2017 23:18, jameskuyper@verizon.net wrote:
> void F(_Bool return)
> {
> if(return)
If this allowed? Ie. using 'return' as an identifier.
> return 1;
Is /this/ allowed? Ie. returning a value in a void function?
> }
> int main(int argc, char *argv[])
> {
> int result = 0;
> if(argc>2)
> result = F(argc>2);
And is /this/ allowed? Ie. using a void return value from a function and
storing it in an int.
(Are we still talking about C here, or some fantasy version?)
> else
> F(argc>2);
> }
>
> This is a dangerous technique, since it's entirely your responsibility to make
> sure that the returned value is used only if a value is returned - the compiler
> does not, in general, have enough information to help you with that. However, it
> is permitted by 6.9.1p12.
6.9.1p12 says this:
"12 If the } that terminates a function is reached, and the value of the
function call is used by the caller, the behavior is undefined."
This rather cryptical message seems to shed no light on the above.
--
bartc
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@verizon.net |
|---|---|
| Date | 2017-09-19 19:40 -0700 |
| Message-ID | <128e86f6-7af7-4b51-94b5-17c37d94aebd@googlegroups.com> |
| In reply to | #120077 |
On Tuesday, September 19, 2017 at 8:21:49 PM UTC-4, Bart wrote:
> On 19/09/2017 23:18, jameskuyper@verizon.net wrote:
>
> > void F(_Bool return)
> > {
> > if(return)
> If this allowed? Ie. using 'return' as an identifier.
No, that was a stupid mistake on my part, which would have been revealed the moment I attempted to compile it, if I'd bothered compiling it. Let's pretend I gave that variable a valid name, such as ret.
> > return 1;
>
> Is /this/ allowed? Ie. returning a value in a void function?
That was another stupid mistake - it was supposed to be "int", but I copied that from Thiago's code without remembering to fix that aspect of it. I only got three hours sleep last night - that's the best defense I can mount.
> > }
>
> > int main(int argc, char *argv[])
> > {
> > int result = 0;
> > if(argc>2)
> > result = F(argc>2);
>
> And is /this/ allowed? Ie. using a void return value from a function and
> storing it in an int.
After correcting the declaration of F to have a return type of 'int', that is allowed.
> (Are we still talking about C here, or some fantasy version?)
Due to my lack of sleep, "fantasy version" seems a plausible explanation, but that was certainly not my intent.
> > else
> > F(argc>2);
> > }
> >
> > This is a dangerous technique, since it's entirely your responsibility to make
> > sure that the returned value is used only if a value is returned - the compiler
> > does not, in general, have enough information to help you with that. However, it
> > is permitted by 6.9.1p12.
>
>
> 6.9.1p12 says this:
>
> "12 If the } that terminates a function is reached, and the value of the
> function call is used by the caller, the behavior is undefined."
>
> This rather cryptical message seems to shed no light on the above.
Does it seem less cryptic now that I've explained my mistakes? After correcting those mistakes, if ret == 0, then the } that terminates F() is reached. However, main() is written in such a way as to guarantee that if ret is 0, then the value of the function call is NOT used, so the behavior is NOT undefined.
Taking an argument that is a pointer to an object to which a return value is optionally written seems like a simpler, safer way to do the same thing - but this approach is permitted.
[toc] | [prev] | [next] | [standalone]
| From | rockbrentwood@gmail.com |
|---|---|
| Date | 2017-09-19 16:36 -0700 |
| Message-ID | <8d57662d-6009-41e8-8f22-4cb75eae6fb4@googlegroups.com> |
| In reply to | #120068 |
On Tuesday, September 19, 2017 at 4:24:04 PM UTC-5, Thiago Adams wrote: > Can I set the result of some void function and get it back? > Not sure, but it seems that you do a "return E;" in a void function, if E is a void expression (e.g. if E is a function call f(x) for a void function f()).
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2017-09-19 22:13 -0400 |
| Message-ID | <opsirk$r21$1@dont-email.me> |
| In reply to | #120076 |
On 09/19/2017 07:36 PM, rockbrentwood@gmail.com wrote: > On Tuesday, September 19, 2017 at 4:24:04 PM UTC-5, Thiago Adams wrote: >> Can I set the result of some void function and get it back? >> > > Not sure, but it seems that you do a "return E;" in a void function, if E is a void expression (e.g. if E is a function call f(x) for a void function f()). That's a constraint violation in C: "A return statement with an expression shall not appear in a function whose return type is void." (6.8.6.4p1) You might be thinking of C++ rules. C++ allows that, because the return type of a function and the type of an expression used in a return statement can both be dependent on template arguments, and there are perfectly legitimate cases for specific values of the template arguments where those types can evaluate to void - as long as both of them are void, that's not a problem.
[toc] | [prev] | [next] | [standalone]
| From | gazelle@shell.xmission.com (Kenny McCormack) |
|---|---|
| Date | 2017-09-22 01:48 +0000 |
| Message-ID | <oq1q4s$nm4$1@news.xmission.com> |
| In reply to | #120076 |
In article <8d57662d-6009-41e8-8f22-4cb75eae6fb4@googlegroups.com>, <rockbrentwood@gmail.com> wrote: >On Tuesday, September 19, 2017 at 4:24:04 PM UTC-5, Thiago Adams wrote: >> Can I set the result of some void function and get it back? >> > >Not sure, but it seems that you do a "return E;" in a void function, if E is a >void expression (e.g. if E is a function call f(x) for a void function f()). BTW, isn't the usual reason for people wanting to do stuff like this - is that they have no control over the "upper level" - i.e., the signature of the funcion they are called upon to write is already determined by some higher level. Yes, this represents poor design - but poor design (both on our own and other's parts) is what keeps food on our tables. -- This is the GOP's problem. When you're at the beginning of the year and you've got nine Democrats running for the nomination, maybe one or two of them are Dennis Kucinich. When you have nine Republicans, seven or eight of them are Michelle Bachmann.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2017-09-19 19:36 -0700 |
| Message-ID | <lnwp4u5c60.fsf@kst-u.example.com> |
| In reply to | #120068 |
Thiago Adams <thiago.adams@gmail.com> 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 <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
| From | mark.bluemel@gmail.com |
|---|---|
| Date | 2017-09-20 01:00 -0700 |
| Message-ID | <c6eec361-f602-4a39-937a-d7c14caeaf83@googlegroups.com> |
| In reply to | #120068 |
On Tuesday, 19 September 2017 22:24:04 UTC+1, Thiago Adams wrote: > Can I set the result of some void function and get it back? Have you tried reading that question out loud to yourself? > I ask just to see if I can put some error code in void functions. If you want to know whether a function succeeded or not, the best bet is for it to return a status surely? Otherwise you have to use a mechanism like errno - remembering to define yourself suitable usage rules like "if you want to test myerrno after a call always zero it before the call" or "if you code a routine to use myerrno, the routine must always set it both on success and on failure".
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2017-09-20 02:01 -0700 |
| Message-ID | <f26bc8c5-bc3a-498a-9a0f-70142fb4ab9b@googlegroups.com> |
| In reply to | #120087 |
W dniu środa, 20 września 2017 10:00:26 UTC+2 użytkownik mark.b...@gmail.com napisał:
> On Tuesday, 19 September 2017 22:24:04 UTC+1, Thiago Adams wrote:
> > Can I set the result of some void function and get it back?
>
> Have you tried reading that question out loud to yourself?
>
> > I ask just to see if I can put some error code in void functions.
>
> If you want to know whether a function succeeded or not, the best
> bet is for it to return a status surely?
>
> Otherwise you have to use a mechanism like errno - remembering to
> define yourself suitable usage rules like "if you want to test
> myerrno after a call always zero it before the call" or "if you
> code a routine to use myerrno, the routine must always set it
> both on success and on failure".
i tried it (i mean errno like mechanism) but abandoned it
- see how i did it in a thread "chunk2int (or str2int) how it SHOULD work?"
i just pass
struct C2I
{
int value;
int failed :1 ;
int more_numbers :1 ;
int polluted_left :1 ;
int polluted_right :1 ;
int out_of_range :1;
};
structure which is 2x int size
and use it like
C2I res = Chunk2Int(words.first[i]);
if(!res.failed) printf(" %15d ", res.value);
if(res.failed) printf(" %15s ", "nil");
if(res.out_of_range) printf(" out of range ");
if(res.more_numbers) printf(" more numbers ");
if(res.polluted_left) printf(" polluted left ");
if(res.polluted_right) printf(" polluted right ");
on longer data to pass i would return pointer to internal static area
[toc] | [prev] | [next] | [standalone]
Page 9 of 10 — ← Prev page 1 … 7 8 [9] 10 Next page →
Back to top | Article view | comp.lang.c
csiph-web