|
From: Ethan M. <merritt@u.washington.edu> - 2005-06-09 17:40:04
|
On Thursday 09 June 2005 12:26 am, Hans-Bernhard Br=F6ker wrote: > Ethan Merritt wrote: >=20 > There's not a lot you could do with strtod() that sscanf() couldn't do=20 > just as well. But slower, apparently. > >>sscanf() and its %n format are used for a reason. >=20 > > But %n is non-portable, as documented by the OSK comment=20 >=20 > Just because some silly implementation is buggy doesn't exactly mean %n=20 > is unportable. %n is as portable as you can ever hope to be: it's an=20 > ANSI requirement. Surely you know the quote about standards: "Standards are nice because there are so many of them...". =20 It turns out that different ANSI revisions describe the behavior of %n differently, so it is not portable. Here is an=20 excerpt from the current man page: "Probably it is wise not to make any assumptions on the effect of %n conversions on the return value." The current code assumes that=20 count =3D sscanf(s, "%lf%n", ...) will set count to 1 if successful, but on some systems it will instead set count to 2. I do not know if this is the specific problem with OSK. strtod() is more portable than %n, and allows more complete=20 error reporting than sscanf(). =20 > I dimly remember this being about not running sscanf() on all columns of= =20 > a multi-column data file if no extended using specs are in use. If you > have "using 1:2:3", you can simply ignore columns 4 to 1000. If you=20 > have "using 1:2:(column(some_function($3)), datafile.c has to convert=20 > all 1000 of them. That is an interesting point, and I now wonder if these optimization lines conflict with the new column-based syntax elements like xticlabels(). I will have to experiment with this. =2D-=20 Ethan A Merritt merritt@u.washington.edu Biomolecular Structure Center Mailstop 357742 University of Washington, Seattle, WA 98195 |