Thorsten Haude [4 Aug 2002 00:38:17 +0200]:
Ich vermute, daß die weitaus meisten Implementierungen am Ende des
Strings aufhören, aber ich vermisse die eindeutige Aussage darüber.
OK, du willst es formell? Das kannst du haben :-) Hier die
entsprechenden Auszüge aus ISO/IEC 9899:1999, besser bekannt als ISO
C99, sprich der derzeit gültige C Standard (ich könnte auch in dem
älteren ANSI C Standard nachschauen, aber da müsste ich erst suchen,
wo ich den habe, die ISO C 99 PDF-Datei ist direkt greifbar:).
Zuerst die Definition von String, Zeiger auf String und Stringlänge:
----------------------------------
7.1.1 Definitions of terms
A string is a contiguous sequence of characters terminated by and
including the first null character. The term multibyte string is
sometimes used instead to emphasize special processing given to
multibyte characters contained in the string or to avoid confusion
with a wide string. A pointer to a string is a pointer to its
initial (lowest addressed) character. The length of a string is the
number of bytes preceding the null character and the value of a
string is the sequence of the values of the contained characters, in
order.
----------------------------------
Und hier die Definition von strcmp:
----------------------------------
7.21.4.2 The strcmp function
Synopsis
#include
int strcmp(const char *s1, const char *s2);
Description
The strcmp function compares the string pointed to by s1 to the string
pointed to by s2.
Returns The strcmp function returns an integer greater than, equal to,
or less than zero, accordingly as the string pointed to by s1 is
greater than, equal to, or less than the string pointed to by s2.
---------------------------------
Aus der Kombination von Definition eines Strings und der Definition
von strcmp ergibt sich *eindeutig*, dass der Vergeich beim Nullbyte
endet.
Um den Unterschied noch zu verdeutlichen, hier die Definition von
strncmp. Man beachte, wie hier von "character array" und "possibly
null terminated character array" gesprochen wird und nicht von
Strings:
---------------------------------
7.21.4.4 The strncmp function
Synopsis
#include
int strncmp(const char *s1, const char *s2, size_t n);
Description
The strncmp function compares not more than n characters (characters
that follow a null character are not compared) from the array pointed
to by s1 to the array pointed to by s2.
Returns
The strncmp function returns an integer greater than, equal to, or
less than zero, accordingly as the possibly null-terminated array
pointed to by s1 is greater than, equal to, or less than the possibly
null-terminated array pointed to by s2.
---------------------------------
Ich hoffe das reicht an formaler Definition :)
Philipp
--
Philipp Thomas work: pthomas@suse.de
Entwicklung, SuSE Linux AG private: philippt@t-online.de