Sujet : Re: Loops (was Re: do { quit; } else { })
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 10. Jun 2025, 14:01:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86jz5jrbrz.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Keith Thompson <Keith.S.Thompson+
u@gmail.com> writes:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
[...]
>
Progarms that manipulate strings using standard library functions
often take advantage of the above. Strings are defined as
null-terminated arrays; but it is very common for strings to be
arrays that are displaced within larger arrays.
>
To be pedantic, a string is defined as "a contiguous sequence of
characters terminated by and including the first null character".
The word "array" is not used. It does seem fairly obvious that
the contiguous sequence will be stored in an array (array
object?), but the standard doesn't quite say so.
Consider the following program:
#include <stdio.h>
#include <string.h>
typedef unsigned long long ULL;
ULL hello = ((((0ULL +'o' <<8) +'l' <<8) +'l' <<8) +'e' <<8) + 'h';
int
main(){
printf( "length is %zu\n", strlen( (char*)&hello ) );
return 0;
}
On a little endian machine (with CHAR_BIT == 8) this program works,
and TTBOMK conforms to both the letter and the spirit of the C
standard, without any undefined behavior (on that platform). Yet
there are no arrays in sight, and certainly no array objects.