bug in strcmp ?

Anything that doesn't fit elsewhere.
Post Reply
jaambros
Posts: 29
Joined: Tue Oct 04, 2005 3:29 pm
Location: Ohio University

bug in strcmp ?

Post by jaambros »

Hi,

I'm getting weird results with strcmp. See below.
It happens with 5.8 and 5.9 in OSX 3.9 and 4 (details below).
However, it seems OK in Linux (details below)
Any idea how to fix this?

Code: Select all

$ uname -a
Darwin firestone.sf.osc.edu 8.8.0 Darwin Kernel Version 8.8.0: Fri Sep  8 17:18:57 PDT 2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc
ohu0256@firestone ~
$ nrniv
NEURON -- Version 5.9  2006-07-14 (1461)
by John W. Moore, Michael Hines, and Ted Carnevale
Duke and Yale University -- Copyright 1984-2005

strcmp( "06o31a-C", "06o31A-C" )
        32 
-----------------
$ uname -a
Darwin axon.zool.ohiou.edu 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC  Power Macintosh powerpc
jose@axon ~/Projects/TraceMatch/TraceSetAnalysis/Results
$ nrniv
NEURON -- Version 5.8 2005-10-7 13:46:29 Main (85)
by John W. Moore, Michael Hines, and Ted Carnevale
Duke and Yale University -- Copyright 1984-2005

oc>strcmp( "06o31a-C", "06o31A-C" )
        32 
-------------
$ uname -a
Linux biowulf 2.4.21-9.0.1.ELamd #2 SMP Tue Jun 15 10:45:33 EDT 2004 i686 athlon i386 GNU/Linux
jose@biowulf ~
$ nrniv
NEURON -- Version 5.9 2006-5-20 18:55:15 Main (39)
by John W. Moore, Michael Hines, and Ted Carnevale
Duke and Yale University -- Copyright 1984-2005

oc>strcmp( "06o31a-C", "06o31A-C" )
       1
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

I checked neuron 5.8 on windows and found the same behavior as Darwin shows.

A non-exhaustive examination of the source code suggests that Neuron is using strcmp implementation that comes with the compiler, and as a result the outcome of strcmp can depend on the compiler/c-library implementation used for compiling neuron.

The opengroup in their description of standard c specify only that strcmp should return an integer and what the sign of this integer should be not the actual value of the integer:
http://www.opengroup.org/onlinepubs/000 ... trcmp.html

Also gnu in their description of libc give teh same guidelines:
http://www.gnu.org/software/libc/manual ... rison.html

Although their examples show the Darwin/Cygwin behavior.

Code: Select all

strcmp ("hello", "hello")
         => 0    /* These two strings are the same. */
     strcmp ("hello", "Hello")
         => 32   /* Comparisons are case-sensitive. */
     strcmp ("hello", "world")
         => -15  /* The character 'h' comes before 'w'. */
     strcmp ("hello", "hello, world")
         => -44  /* Comparing a null character against a comma. */
     strncmp ("hello", "hello, world", 5)
         => 0    /* The initial 5 characters are the same. */
     strncmp ("hello, world", "hello, stupid world!!!", 5)
         => 0    /* The initial 5 characters are the same. */
The source and hoc code for version 5.8 and build 1419 of 5.9 contain no obvious errors regarding the USE of strcmp. As one might expect, because Neuron and especially the GUI seem to run without problems on platforms using the different strcmp conventions.

Conclusion:
1. If you want to write portable hoc-code you will have to test the sign of the output of strcmp not the value.
2. The Neuron documentation http://www.neuron.yale.edu/neuron/stati ... tml#strcmp contains a bug in that it specifies the values strcmp returns and not the signs.

Alternative conclusion:
The mapping from strcmp in the c-libarary to a hoc function needs to be adjusted to fit the description in the quick-reference.
hines
Site Admin
Posts: 1710
Joined: Wed May 18, 2005 3:32 pm

Post by hines »

The documentation was sloppy on that
point and now reads:
"return negative, 0, or positive value depending..."
Post Reply