Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #112825
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Warning: assignment from incompatible pointer type |
| Date | 2017-06-22 11:03 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87podw8hky.fsf@bsb.me.uk> (permalink) |
| References | (2 earlier) <oic978$qkf$3@dont-email.me> <87o9ti9mlt.fsf@bsb.me.uk> <oicier$fvg$2@dont-email.me> <oidlf0$gne$1@dont-email.me> <oif9q6$s7i$2@dont-email.me> |
DFS <nospam@dfs.com> writes:
> On 6/21/2017 7:35 AM, David Brown wrote:
>> On 21/06/17 03:37, DFS wrote:
<snip>
>>> Mainly I love the blazing execution speed of C.
>>>
>>
>> The speed of a program comes from many things. The algorithm used is
>> often more important than the language, and the speed of the tool's
>> libraries can be a big effect. Python excels at string handling,
>> searching and sorting - in some cases a few lines of Python code will
>> run faster than a C program for the job.
>
> python is slow at everything I've ever tried. A sed line will execute
> 4x faster than python (say to do some word replacements or swaps). C
> is 20x faster on avg I would say.
There are other speeds to consider. The speed with with a program can
be written in the first place is probably the most significant, but also
how quickly it can be adapted to new requirements, how fast it can be
understood by others, and so on.
> But python is easy to learn, and has a big bunch of libraries. And I
> love the python list comprehension.
>
> One line to count the unique characters in a string.
>
> msg = "Now is the time for all good men to come to the aid of their country"
> for t in sorted(set([(x,msg.count(x)) for x in msg])):
> print t[0],t[1]
If you like speed, you might want to write
for t in sorted([(x,msg.count(x)) for x in set(msg)]):
instead. (Personally, I'd write
for (letter, count) in sorted([(l, msg.count(l)) for l in set(msg)]):
print(letter, count)
because (a) Python3 and (b) I like destructuring binds.)
<snip>
>> ... Do you have
>> particular projects that interest you?
>
> The one I created recently is interesting. It reads in a .csv file
> and summarizes and pivots the data (exactly like a pivot table in a
> spreadsheet). Doing it answered the question "How is it done?" With
> not much difficulty, it turns out.
The code you posted probably has at least one bug. I am not entirely
sure where it is, but valgrind reports a problem and valgrind is very
rarely wrong. (I'm sorry I can't be more helpful but I investigated for
a while and then time got the better of me).
Also it if full of bugs waiting to happen since none of your string
operations are length limited and I'm not sure all the other array
accesses are properly checked either. I mention this not to be mean (as
I have been accused of being) but because it might be significant to a
discussion of time -- if you are writing a one-off "see how it could be
done" program, you would have finished long ago using a scripting
language, but if you want to write a re-usable, reliable utility program
you are no where near finished yet. Doing so would show you how much
time is needed to write robust C code.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 12:48 -0400
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-20 18:08 +0100
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-21 09:32 -0400
Re: Warning: assignment from incompatible pointer type scott@slp53.sl.home (Scott Lurndal) - 2017-06-21 13:48 +0000
Re: Warning: assignment from incompatible pointer type Richard Heathfield <rjh@cpax.org.uk> - 2017-06-20 18:15 +0100
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 18:00 -0400
Re: Warning: assignment from incompatible pointer type "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-20 18:47 -0400
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-21 00:10 +0100
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 19:56 -0400
Re: Warning: assignment from incompatible pointer type "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-20 13:23 -0400
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 18:59 -0400
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-20 19:23 +0100
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 18:59 -0400
Re: Warning: assignment from incompatible pointer type Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-20 19:46 -0400
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-21 02:05 +0100
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-20 21:37 -0400
Re: Warning: assignment from incompatible pointer type Richard Heathfield <rjh@cpax.org.uk> - 2017-06-21 09:25 +0100
Re: Warning: assignment from incompatible pointer type David Brown <david.brown@hesbynett.no> - 2017-06-21 13:35 +0200
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-21 22:30 -0400
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-22 11:03 +0100
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 11:10 +0100
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 11:42 +0100
Re: Warning: assignment from incompatible pointer type David Brown <david.brown@hesbynett.no> - 2017-06-22 13:49 +0200
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 14:40 +0100
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 17:00 +0100
Re: Warning: assignment from incompatible pointer type David Brown <david.brown@hesbynett.no> - 2017-06-22 20:08 +0200
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-22 15:46 -0400
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-22 14:00 +0100
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 14:38 +0100
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-22 17:26 +0100
Re: Warning: assignment from incompatible pointer type Keith Thompson <kst-u@mib.org> - 2017-06-22 10:21 -0700
Re: Warning: assignment from incompatible pointer type bartc <bc@freeuk.com> - 2017-06-22 18:26 +0100
Re: Warning: assignment from incompatible pointer type David Brown <david.brown@hesbynett.no> - 2017-06-22 20:41 +0200
Re: Warning: assignment from incompatible pointer type Richard Heathfield <rjh@cpax.org.uk> - 2017-06-22 19:59 +0100
Re: Warning: assignment from incompatible pointer type Keith Thompson <kst-u@mib.org> - 2017-06-22 12:28 -0700
Re: Warning: assignment from incompatible pointer type Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-21 09:49 -0400
Re: Warning: assignment from incompatible pointer type DFS <nospam@dfs.com> - 2017-06-21 10:36 -0400
Re: Warning: assignment from incompatible pointer type Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-21 14:15 -0400
Re: Warning: assignment from incompatible pointer type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-21 15:10 +0100
csiph-web