Discussion:
Is unsigned long and unsigned int also the same on 64 bit PC gcc systems?
(too old to reply)
Jan Panteltje
2005-03-01 19:57:22 UTC
Permalink
I got finally confused about this,
reading libc, info I am not so sure...

It is the same on my 32 bit system:
fprintf(stderr, "unsigned int max=%u unsigned long max=%lu\n", UINT_MAX, ULONG_MAX);
gives:
unsigned int max=4294967295 unsigned long max=4294967295

But I have no 64 bit system to test.

size_t changes I know.
Måns Rullgård
2005-03-01 20:10:29 UTC
Permalink
Post by Jan Panteltje
I got finally confused about this,
reading libc, info I am not so sure...
fprintf(stderr, "unsigned int max=%u unsigned long max=%lu\n",
UINT_MAX, ULONG_MAX);
unsigned int max=4294967295 unsigned long max=4294967295
But I have no 64 bit system to test.
size_t changes I know.
The most common on 64-bit systems is 32-bit int and 64-bit long. For
portable code, never assume anything about the sizes.
--
Måns Rullgård
***@inprovide.com
Jan Panteltje
2005-03-01 20:29:01 UTC
Permalink
On a sunny day (Tue, 01 Mar 2005 21:10:29 +0100) it happened
Post by Måns Rullgård
Post by Jan Panteltje
I got finally confused about this,
reading libc, info I am not so sure...
fprintf(stderr, "unsigned int max=%u unsigned long max=%lu\n", UINT_MAX, ULONG_MAX);
unsigned int max=4294967295 unsigned long max=4294967295
But I have no 64 bit system to test.
size_t changes I know.
The most common on 64-bit systems is 32-bit int and 64-bit long. For
portable code, never assume anything about the sizes.
Thank you :-)
Chris McDonald
2005-03-01 20:33:09 UTC
Permalink
Post by Måns Rullgård
Post by Jan Panteltje
I got finally confused about this,
reading libc, info I am not so sure...
fprintf(stderr, "unsigned int max=%u unsigned long max=%lu\n", UINT_MAX, ULONG_MAX);
unsigned int max=4294967295 unsigned long max=4294967295
But I have no 64 bit system to test.
size_t changes I know.
The most common on 64-bit systems is 32-bit int and 64-bit long. For
portable 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.

______________________________________________________________________________
Dr Chris McDonald E: ***@csse.uwa.edu.au
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089
p***@yahoo.com
2005-03-02 14:46:34 UTC
Permalink
Post by Chris McDonald
Post by Måns Rullgård
The most common on 64-bit systems is 32-bit int and 64-bit long.
For
Post by Chris McDonald
Post by Måns Rullgård
portable 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.

Continue reading on narkive:
Loading...