Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Les Cargill <lcargill99@comcast.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: I need to vent some steam |
| Date | 2015-03-06 08:17 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <mdccki$md8$1@dont-email.me> (permalink) |
| References | <20150305170109.221d04fe@geostat.dk> <R1iKw.531221$dw5.387832@fx25.iad> |
Richard Damon wrote:
> On 3/5/15 11:01 AM, Anders Wegge Keller wrote:
>> While porting the code for a rather large airport from SCO to Linux,
>> I've
>> come across this example of "Which wheel do you want to reinvent today?"
>>
>> char *pint(char *buf, int len, int val) {
>> int dval;
>>
>> for (len--; len >= 0; len--) {
>> dval = val % 10;
>> val -= dval;
>> buf[len] = (char)('0' + dval);
>> val /= 10;
>> }
>> return buf;
>> }
>>
>> The whole code base is filled with dubious constructs like this,
>> encompassing a strange mix of programming paradigms, including what looks
>> like an attempt at functional programming via RPC calls. This gem was the
>> straw that broke the camel's back.
>>
>
> I will have to say that I have built functions like that in my code, and
> in some applications it is very justified.
>
> Much of my code ends up in embedded processors with limited resources
> and are multi-threaded with real time requirements. In many cases the
> solution of "use printf and friends" is not applicable. The printf
> family is a monster, it can pull in a lot of library code (like the
> floating point library, though some platforms will allow you to use a
> downgraded version that omits floating point). It can also you a lot of
> stack space and may not be thread safe.
>
In general, if the thing is small enough to worry about these issues,
thread safety should not be at issue ( all operation should be
run-to-completion ). You're mainly defending the main
loop from the ISRs and there's just no good way to do that except
manually - you have to enforce consumer/producer relationships in
a manner that is tractable by inspection.
Hoisting in mass quantities of code is a real problem, but it's
something you can measure for. And it's been a long time since having
to have the floating point library was a problem for me
personally.
As ... hazardous as floating point is, it can also be frequently more
correct than fixed point and easier to read.
> Having a few functions like this instead of printf may be a big win for
> the application size.
>
It certainly can be.
> Now, in your case, if you are running under a "real" operating system,
> you likely have a lot more resources so this shouldn't be an issue.
>
> One big question is "How old is this code base?", I could see that there
> could be pieces old enough in there that it predates being on a bigger
> processor and you may be seeing remnants of the space saving I was
> talking about. If it is really old, it could that some of what you think
> of as "standard", weren't practically available (sprintf goes back a
> long ways, but some of the early versions gave you reasons to want to
> use something else if practical).
>
I am thinking that in this case the suite of routines surrounding atoi()
and itoa() should be enough to get things done. That would be my
starting place, anyway.
atoi() & itoa() proper are deprecated and there are
replacements for them.
Still, there are basic style issues with the shown example. It's
relatively hard to understand - not in a despair inducing way,
more like a "rock in your shoe" way.
> The mix of paradigms is a likely indicator of this too, it probably has
> gone through a bunch of hands, and unless you are really going to go
> through and rewrite the whole thing, you may well add another one or two
> to the mix.
--
Les Cargill
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I need to vent some steam Anders Wegge Keller <wegge@geostat.dk> - 2015-03-05 17:01 +0100
Re: I need to vent some steam Morris Dovey <mrdovey@iedu.com> - 2015-03-05 10:32 -0600
Re: I need to vent some steam Richard Heathfield <rjh@cpax.org.uk> - 2015-03-05 17:04 +0000
Re: I need to vent some steam Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-05 17:42 +0000
Re: I need to vent some steam glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-05 19:16 +0000
Re: I need to vent some steam jacob navia <jacob@spamsink.net> - 2015-03-05 20:47 +0100
Re: I need to vent some steam Anders Wegge Keller <wegge@geostat.dk> - 2015-03-05 20:52 +0100
Re: I need to vent some steam Kaz Kylheku <kaz@kylheku.com> - 2015-03-05 22:20 +0000
Re: I need to vent some steam Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-05 17:51 +0000
Re: I need to vent some steam Kaz Kylheku <kaz@kylheku.com> - 2015-03-05 22:20 +0000
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-05 23:14 -0800
Re: I need to vent some steam Bartc <bc@freeuk.com> - 2015-03-06 10:41 +0000
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-06 08:03 -0800
Re: I need to vent some steam Bartc <bc@freeuk.com> - 2015-03-06 16:50 +0000
Re: I need to vent some steam Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-06 15:32 -0800
Re: I need to vent some steam Öö Tiib <ootiib@hot.ee> - 2015-03-07 07:59 -0800
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-07 16:22 -0800
Re: I need to vent some steam James Kuyper <jameskuyper@verizon.net> - 2015-03-07 19:45 -0500
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-07 17:21 -0800
Re: I need to vent some steam Bartc <bc@freeuk.com> - 2015-03-08 10:29 +0000
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-08 13:37 -0700
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-07 16:20 -0800
Re: I need to vent some steam Anders Wegge Keller <wegge@geostat.dk> - 2015-03-06 17:54 +0100
Re: I need to vent some steam Geoff <geoff@invalid.invalid> - 2015-03-06 09:58 -0800
Re: I need to vent some steam Morris Dovey <mrdovey@iedu.com> - 2015-03-07 02:29 -0600
Re: I need to vent some steam Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-07 11:01 +0000
Re: I need to vent some steam Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 10:46 -0700
Re: I need to vent some steam Richard Damon <Richard@Damon-Family.org> - 2015-03-06 08:34 -0500
Re: I need to vent some steam Les Cargill <lcargill99@comcast.com> - 2015-03-06 08:17 -0600
Re: I need to vent some steam Keith Thompson <kst-u@mib.org> - 2015-03-06 08:02 -0800
Re: I need to vent some steam Richard Damon <Richard@Damon-Family.org> - 2015-03-06 22:38 -0500
Re: I need to vent some steam Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-06 15:44 -0800
Re: I need to vent some steam Ian Collins <ian-news@hotmail.com> - 2015-03-07 13:35 +1300
Re: I need to vent some steam Ian Collins <ian-news@hotmail.com> - 2015-03-07 07:42 +1300
Re: I need to vent some steam raltbos@xs4all.nl (Richard Bos) - 2015-03-06 22:51 +0000
Re: I need to vent some steam Michael Angelo Ravera <maravera@prodigy.net> - 2015-03-06 16:48 -0800
Re: I need to vent some steam Xcott Craver <xcottcraver@gmail.com> - 2015-03-09 08:52 -0700
Re: I need to vent some steam Anders Wegge Keller <wegge@geostat.dk> - 2015-03-09 21:11 +0100
Re: I need to vent some steam Kaz Kylheku <kaz@kylheku.com> - 2015-03-09 20:16 +0000
Re: I need to vent some steam Anders Wegge Keller <wegge@geostat.dk> - 2015-03-09 21:38 +0100
Re: I need to vent some steam Kaz Kylheku <kaz@kylheku.com> - 2015-03-09 20:54 +0000
Re: I need to vent some steam David Brown <david.brown@hesbynett.no> - 2015-03-10 09:02 +0100
Re: I need to vent some steam Robert Wessel <robertwessel2@yahoo.com> - 2015-03-10 05:34 -0500
Re: I need to vent some steam Robert Wessel <robertwessel2@yahoo.com> - 2015-03-09 19:15 -0500
Re: I need to vent some steam Keith Thompson <kst-u@mib.org> - 2015-03-10 07:55 -0700
csiph-web