[techtalk] switch function in C (or how to read commandline args?)

Conor Daly conor.daly at oceanfree.net
Mon Jul 2 01:33:50 EST 2001


Thanks James and Jeff for the thoughts.  It kinda looks like an if else-if
chain is my only option.

On Sat, Jun 30, 2001 at 08:05:04PM -0500 or so it is rumoured hereabouts, 
Jeff Dike thought:
> James Sutherland <jas88 at cam.ac.uk> said:
> > Also, from an aesthetic point of view, a single block of strcmp()s
> > will bring my lunch back.
> 
> A chain of strcmps has one huge advantage - it's basically impossible to get 
> wrong once one has been done right.  Aesthetics don't matter to me as much as 
> code that's obviously right.
 
Good point, though, as James says, it ain't that pretty!

> > Besides, using someone else's library 
Especially if the library isn't available for the box on which the final
program will run.  

> > doesn't answer the more general
> > question of "how do I do a switch()-like operation on a set of
> > strings?" - a question I'm dealing with in another context at the
> > moment... 
> 
> If it really is performance critical to switch on strings, it's fairly likely 
> that it's because you're having to continuously switch on the same strings.  
> In that case, converting the strings to tokens once and switching on the 
> tokens is probably a decent way to go.

Now that's interesting.  So how do I tokenise the strings?

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
  1:22am  up 17 days,  1:39,  0 users,  load average: 0.13, 0.03, 0.01
Hobbiton.cod.ie
  1:29am  up 17 days,  1:46,  1 user,  load average: 0.00, 0.03, 0.02




More information about the Techtalk mailing list