Post by Chris McDonaldPost by Måns RullgårdThe most common on 64-bit systems is 32-bit int and 64-bit long.
For
Post by Chris McDonaldPost by Måns Rullgårdportable code, never assume anything about the sizes.
Agreed. If you *require* a 64-bit datatype, do not make assumptions
about whether a simple int or long or long long will provide it.
Use a C compiler supporting the <stdint.h> header file
(such as gcc -std=c99 ...) and, if you want a 64-bit int,
declare it as int64_t and use constants such as INT64_MAX.
I still am having some surprized, I tried the following code:
size_t longest_input_file_length;
uint16_t aaq1;
longest_input_file_length = UINT_MAX; //s
fprintf(stderr, "longest_input_file_length=%u\n",
longest_input_file_length);
aaq1 = longest_input_file_length;
fprintf(stderr, "%u", aaq1);
This, on my 32 bit system, results in:
longest_input_file_length=4294967295
65535
and no compile warning with -Wall.
But size_t is 32 bit on this system!
However, if I write:
fprintf(stderr, "longest_input_file_length=%lu\n",
longest_input_file_length);
Then the result is the same when running the program, but now I get a
compile
warning:
warning: long unsigned int format, size_t arg (arg 3)
But 'long unsigned int' was the same as 'unsigned int'!
In the first case I would have expected a warning, as I clearly violate
sizes, by assigning a 32 bits to a 16 bits value, but no warning.
In the second case it warns in printf() if there is no violation?
What I am trying to find out is what happens if somebody compiles my
stuff
on a 64 bit (or other architecture) machine.
It is a small audio program,
http://panteltje.com/panteltje/dvd/multimux-test.tgz
You will see the defines in wave_header.h now all as for example
uint32_t sample_fq; /* Sample Freq */
as the wave header structure must be maintained.