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.
Am 10.06.2025 um 15:01 schrieb Tim Rentsch:
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.
There are not much remaining big-endian architectures today.
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 10.06.2025 um 15:01 schrieb Tim Rentsch:
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.
There are not much remaining big-endian architectures today.
Ethernet is big-endian at the byte level and little-endian
at the bit level.
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 10.06.2025 um 15:01 schrieb Tim Rentsch:
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.
There are not much remaining big-endian architectures today.
Ethernet is big-endian at the byte level and little-endian
at the bit level.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 163:51:38 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
9,181 files (2,736M bytes) |
Messages: | 2,411,515 |