RE: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-04-06 09:36:29
|
Question about C99. That is a first! See below:
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Roberto Ricardi
> Sent: Sunday, April 06, 2003 2:11 AM
> To: 'Dev-C++ -Users-List'
> Subject: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
>=20
>=20
> Hi all,
>=20
> Can I handle 64 bits numbers with unsigned long long ?
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <conio.h>
>=20
> unsigned long long int D0,D1 ;
> =20
> int main(int argc, char *argv[])
> {
> D0 =3D 0;
> D1 =3D 0xffffffffffff; /* I put first unsigned long int, compiler=20
> alerts about truncated number...) */
> gotoxy(1,9);printf ("Num hexa : ");
> scanf ("%x",&D0); /*can handle whatever up to 32 bits*/
> gotoxy(1,11);printf ("Dec0: %lu\nDec1: %lu\n\n", D0, D1);
> =20
> getchar(); getchar();
> return 0;
> }
> /*
> Results:
>=20
> Dec0 : 4294967295 mean ok if I put just up to 0xffffffff 32bits
> Dec1 : 0 ??
> */
>=20
> Why is ever truncated in 32 bits, how can handle long long to=20
> get up to=20
> 64 bits numbers ?
unsigned long long is not guaranteed to be 64-bit. If you want an =
unsigned
integral type to be at least 64-bit, you have to do:
#include <stdint.h>
// ...
uint_least64_t D0, D1;
// ...
which is a typedef of the closest to 64-bit type provided by platform
(closest from above, that is if unsigned long is 32 bit and unsigned =
long
long is 128 bit for example, the typedef will be of unsigned long long).
I read it straight from the standard. I do not know whether MINGW has
implemented it (and as far as I know these facilities are "optional", if =
the
platform doesn't support >=3D64 bit, will not have the above type =
naturally).
By the way, have you got any book regarding C99? If yes, can you please =
tell
me which?
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|