Скажите как можно хранить и оперировать целыми большими чем 4-х байтным long'ом.
Что такое unsigned long long. Сколько байт на него отводится и как с ним работать (отобразать printf, записывать scanf)?Заранее спасибо
>Скажите как можно хранить и оперировать целыми большими чем 4-х байтным long'ом.
>
>Что такое unsigned long long. Сколько байт на него отводится и как
>с ним работать (отобразать printf, записывать scanf)?
>
>Заранее спасибоHi,
As i remember long long types are 64 bit. Since there is not much standards regarding them gcc implements (q,L,ll) arguments. When i'm talking about not too much standards i mean different platforms (for example "q" in BSD), different compilers and their versions.
Below you can find small example for my gcc (2.96 on linux)
#define __STDC_VERSION__ 199901L
#include <limits.h>
#include <stdio.h>int main( int argc, char** argv )
{
unsigned long long ull = LLONG_MAX;
char res[ 50 ];printf( "ull=%llu\n", ull );
printf( "ull=%qu\n", ull );
sprintf( res, "%Lu", ull );
printf( "res=%s\n", res );
sprintf( res, "%qu", ull );
printf( "res 2=%s\n", res );return 0;
}Hope it helps
--- sas
>As i remember long long types are 64 bit. Since there is
>not much standards regarding them gcc implements (q,L,ll) arguments. When
>i'm talking about not too much standards i mean different
>platforms (for example "q" in BSD), different compilers and their versions.
>
>
>Below you can find small example for my gcc (2.96 on linux)
>
>
>
>#define __STDC_VERSION__ 199901L
>#include <limits.h>
>#include <stdio.h>
>
>int main( int argc, char** argv )
>{
> unsigned long long ull = LLONG_MAX;
> char res[ 50 ];
>
> printf( "ull=%llu\n", ull );
> printf( "ull=%qu\n", ull );
> sprintf( res, "%Lu", ull );
> printf( "res=%s\n", res );
> sprintf( res, "%qu", ull );
> printf( "res 2=%s\n", res );
>
> return 0;
>}
>
>Hope it helps
>--- sasThank you for help. On FBSD 4.6 long long work right with %qu for Xscanf() and %llu (or %qu) for Xprintf()
Ja tak dumaju, chto v 32-bit sistemah tip "int" imeet 32 razrjada (kak "long" v 16-bit sistemah tipa DOS). A tseloe na 64 razrjada - eto "long". Jasnoe delo, modifikator "unsigned" mozhno prilepit' i k "int" i k "long". I dlja vvoda/vivoda dostatocho formata "%lu".PS. Vopros ne po teme, no objasnjaet translit.
Imeetsja "vncserver" na Linux, "vncviewer" na W2000. Rabotaet normal'no, russkij vidno,no pri popitke vvoda russkogo on otobrazhaetsja znakami voprosa ("?"). Na neposredstvenno na linux-mashine v X vse rabotaet.
Kto-nibud' znaet, kak eto lechitsja ?
Hi XMAN,Regarding data sizes below you will see quote from ISO/IEC 9899:1999
standard. So int/long are 32 bits.//////////////////////////////////////////////////////////
-- number of bits for smallest object that is not a bit-field (byte)
CHAR_BIT 8
-- minimum value for an object of type signed char
SCHAR_MIN -127 // -(2^7 - 1)
-- maximum value for an object of type signed char
SCHAR_MAX +127 // 2^7 - 1
-- maximum value for an object of type unsigned char
UCHAR_MAX 255 // 2^8 - 1
-- minimum value for an object of type char
CHAR_MIN see below
-- maximum value for an object of type char
CHAR_MAX see below
-- maximum number of bytes in a multibyte character, for any supported
MB_LEN_MAX 1
-- minimum value for an object of type short int
SHRT_MIN -32767 // -(2^15 - 1)
-- maximum value for an object of type short int
SHRT_MAX +32767 // 2^15 - 1
-- maximum value for an object of type unsigned short int
USHRT_MAX 65535 // 2^16 - 1
-- minimum value for an object of type int
INT_MIN -32767 // -(2^15 - 1)
-- maximum value for an object of type int
INT_MAX +32767 // 2^15 - 1
-- maximum value for an object of type unsigned int
UINT_MAX 65535 // 2^16 - 1
-- minimum value for an object of type long int
LONG_MIN -2147483647 // -(2^31 - 1)
-- maximum value for an object of type long int
LONG_MAX +2147483647 // 2^31 - 1
-- maximum value for an object of type unsigned long int
ULONG_MAX 4294967295 // 2^32 - 1
-- minimum value for an object of type long long int
LLONG_MIN -9223372036854775807 // -(2^63 - 1)
/////////////////////////////////////////////////////////Regarding vnc question do not know. Just a wild guess: check out locale and
fonts.Thanks
--- SasPS. It took some time for me to read and understand your "razrjadov" :)
>Ja tak dumaju, chto v 32-bit sistemah tip "int" imeet 32 razrjada
>(kak "long" v 16-bit sistemah tipa DOS). A tseloe na 64
>razrjada - eto "long". Jasnoe delo, modifikator "unsigned" mozhno prilepit' i
>k "int" i k "long". I dlja vvoda/vivoda dostatocho formata "%lu".
>
>
>PS. Vopros ne po teme, no objasnjaet translit.
>Imeetsja "vncserver" na Linux, "vncviewer" na W2000. Rabotaet normal'no, russkij vidno,no pri
>popitke vvoda russkogo on otobrazhaetsja znakami voprosa ("?"). Na neposredstvenno na
>linux-mashine v X vse rabotaet.
>Kto-nibud' znaet, kak eto lechitsja ?
Heh. Tak tut:-- maximum value for an object of type unsigned int
UINT_MAX 65535 // 2^16 - 1to est' 16 bit :))
Erunda kakaja-to poluchaetsja. ULONG_MAX dejstvitel'no 32-bit, a UINT_MAX sovsem ne 16, a tozhe 32.
Chto kasaetsja 64 bit - v chem-to ti bil prav :))
On my machine with FBSD 4.6 next code:
/* skiped */
short s;
int i;
long l;
long long ll;printf ("\nshort=%i int=%i long=%i longlong=%i\n",sizeof(s),sizeof(i),sizeof(l),sizeof(ll));
/* skiped */
gave me this result:short=2 int=4 long=4 longlong=8