Article View: alt.privacy.anon-server
Article #46677Re: Free reliable wordcount utility available (final version)
From: Richard Heathfield
Date: Fri, 08 Nov 2002 19:19
Date: Fri, 08 Nov 2002 19:19
65 lines
4088 bytes
4088 bytes
"Thomas J. Boschloo" wrote:
>
> Benjamin Goldberg wrote:
> >
> > Thomas J. Boschloo wrote:
> > >
> > > Benjamin Goldberg wrote:
>
> > > > extern void func( int * x );
> > > > #define FUNC() (int)({ int t; func(&t); t; })
> > > >
> > > > ....
> > > > int z = FUNC();
> > > > other_function( FUNC() );
> > >
> > > This looks flawed to me, but probably you are doing something clever.
> > > What is 't'? Some variable? You can't define variables at any position
> > > you like in ANSI-C AFAIK, that is C++.
> >
> > You can declare variables at the beginning of a block. Note the ({})
> > construct has a pair of {} in it? So what you've got, is a block with a
> > pair of parenthesis around it, and a cast in front of those parens.
>
> I still think it is dangerous, even if it is allowed in ANSI-C.
The macro Benjamin showed you is not allowed in ISO C (or, if you
prefer, ANSI C - much of a muchness). But the block-scoped variable *is*
allowed.
> E.g.
> what if the procedure you use FUNC() in already uses a variable 't'?
What if it does? The macro creates its own local variable, which it will
use in preference to a wider-scoped variable with the same name.
Using the macro makes your program non-portable, though, which is
sufficient reason not to use it (in my opinion).
> You
> will get a compiler warning of course, but then again, you might not.
For the block-scope variable shadowing a wider-scope variable? No
implementation is *required* to diagnose it, since it is neither a
syntax error nor a constraint violation. Any implementation is *allowed*
to diagnose it, if it wishes.
<snip>
> I just ran that version of my wordcnt utility on my 100mb swapfile from
> MS-Dos. If finished well within a full hour :-) That is a lot less then
> I expected at first. I ran out of memory though.. 300000 words counted I
> believe, lot's of MICROSOFT strings in my swapfile ;-P
You'll be glad to know that you should be able to make it a lot faster.
I just spent about half an hour writing a C++ version (C++ is considered
by many, including me, to be slower than C), and it runs at a little
over twice the speed of yours (on the same hardware, of course).
If you want the source code, let me know.
--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Technical Details
Message-ID:
<3DCC0E5A.4C70F9F@eton.powernet.co.uk>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.security.pgp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!demon!easynet-monga!easynet.net!news2.power.net.uk!news.power.net.ukReferences:
<3DC1596C.6D2B55BD@hccnet.nl.invalid> <3DC526FC.CBCFE9B6@hccnet.nl.invalid> <3DC5451F.DBF3CDDA@eton.powernet.co.uk> <pan.2002.11.03.17.05.02.482162@yahoo.co.uk> <3DC81975.45915377@hccnet.nl.invalid> <3DC85EA2.2C8E26DA@earthlink.net> <3DC95533.512AB0A3@hccnet.nl.invalid> <3DC976DA.32815A18@earthlink.net> <3DCBC0A8.F3785708@hccnet.nl.invalid>Show Full Headers
Complete Article Headers
Message-ID: <3DCC0E5A.4C70F9F@eton.powernet.co.uk> Subject: Re: Free reliable wordcount utility available (final version) Date: Fri, 08 Nov 2002 19:19:54 +0000 From: Richard Heathfield <binary@eton.powernet.co.uk> References: <3DC1596C.6D2B55BD@hccnet.nl.invalid> <3DC526FC.CBCFE9B6@hccnet.nl.invalid> <3DC5451F.DBF3CDDA@eton.powernet.co.uk> <pan.2002.11.03.17.05.02.482162@yahoo.co.uk> <3DC81975.45915377@hccnet.nl.invalid> <3DC85EA2.2C8E26DA@earthlink.net> <3DC95533.512AB0A3@hccnet.nl.invalid> <3DC976DA.32815A18@earthlink.net> <3DCBC0A8.F3785708@hccnet.nl.invalid> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.security.pgp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!demon!easynet-monga!easynet.net!news2.power.net.uk!news.power.net.uk Organization: Eton Computer Systems Ltd X-Mailer: Mozilla 4.6 [en-gb]C-CCK-MCD NetscapeOnline.co.uk (WinNT; I) X-Accept-Language: en-GB,en MIME-Version: 1.0 Newsgroups: alt.privacy.anon-server,sci.crypt,alt.fan.cult-dead-cow,alt.security.pgp Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 195.60.5.99 X-Trace: news.power.net.uk 1036783550 195.60.5.99 (8 Nov 2002 19:25:50 GMT) Lines: 67