Liste des Groupes | Revenir à cl c |
Waldek Hebisch <antispam@fricas.org> writes:Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:Waldek Hebisch <antispam@fricas.org> writes:>Bart <bc@freeuk.com> wrote:[...]I had a problem with this code because it was so verbose. The first>
thing I did was to define aliases u64 and u32 for those long types:
typedef unsigned long long u64;
typedef unsigned long u32;
This code runs in 33 bit i386, 32 bit ARM and 64 bit x86-64, in
all cases under Linux. As Keith noticed, most popular of those
has 64-bit long. So your definition would break it. You need
>
typedef unsigned int u32;
Just add #include <stdint.h> and use uint32_t -- or, if you value
brevity for some reason:
typedef uint32_t u32;
(Bart dislikes <stdint.h>, but there's no reason you should.)
1. Well, I used to care about pre-Ansi compilers and for benefit
to them I got into habit of avoiding <stdint.h>. Yes, it is time
to change and on microcontrollers I use <stdint.h> as sizes
are important there and I do not expect to ever compile
microcontroller code with non-Ansi compiler.
Pre-ANSI? I haven't been even been able to find a working pre-ANSI
C compiler.
<stdint.h> was added in C99, so a C89/C90 ("ANSI") implementation might
not support it, but I'd still be surprised if you could find a C
implementatation these days that doesn't have <stdint.h>. And you can
roll your own or use something like
<https://www.lysator.liu.se/c/q8/index.html>.
2. As I explanined fixed size is just current state of developement.
On 64-bit machines code should use bigger types. And to get
128-bit type it seems that I need nonstandard type (there seem
to be new types in C23, but I did not investigate them deeper).
C23 doesn't add any new support for 128-bit integers.
gcc (and compilers intended to be compatible with it, like clang)
support __int128 and unsigned __int128 types, but only on 64-bit
systems, and they're not strictly integer types (for example, there are
no constants of type __int128).
Les messages affichés proviennent d'usenet.