long long int 
Author Message
 long long int

hi. i'm not sure this is a compiler issue or not, but here goes. i have the
following code:

#include <stdio.h>

unsigned long long int array[2];

void main()
{
    array[0] = 20020505141502; //have tried suffixing with ull and ULL
    array[1] = 20021018040416;

    for (int i=0;i<2;i++) {
        printf("string %d: %Lu\n", i, array[i]);
    }

Quote:
}

and it prints:

string 0: 1662574846
string 1: 2175473760

am i doing something wrong?

thanx in advance



Fri, 20 May 2005 11:52:32 GMT  
 long long int

wrote in comp.lang.c:

Quote:
> hi. i'm not sure this is a compiler issue or not, but here goes. i have the
> following code:

> #include <stdio.h>

> unsigned long long int array[2];

> void main()
> {

Actually your entire program has undefined behavior due to the illegal
"void main()", so anything it does is OK as far as the C language is
concerned.

main() returns int.  ALWAYS.

Quote:
>     array[0] = 20020505141502; //have tried suffixing with ull and ULL
>     array[1] = 20021018040416;

>     for (int i=0;i<2;i++) {
>         printf("string %d: %Lu\n", i, array[i]);
>     }
> }

> and it prints:

> string 0: 1662574846
> string 1: 2175473760

> am i doing something wrong?

> thanx in advance

Aside from the "void main()", yes you are doing something else wrong.
Who told you that "%Lu" was the printf() conversion specifier for
unsigned long long?  The conversion specifiers are the same as for
long with an extra lower case 'l', that is:

%lld (signed long long as decimal)
%llu (unsigned long long as decimal)
%llx (unsigned long long as hex)

...and so on.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq



Fri, 20 May 2005 12:56:43 GMT  
 long long int

Quote:

> hi. i'm not sure this is a compiler issue or not, but here goes. i have the
> following code:

> #include <stdio.h>

> unsigned long long int array[2];

> void main()
> {
>     array[0] = 20020505141502; //have tried suffixing with ull and ULL
>     array[1] = 20021018040416;

>     for (int i=0;i<2;i++) {
>         printf("string %d: %Lu\n", i, array[i]);
>     }
> }

> and it prints:

> string 0: 1662574846
> string 1: 2175473760

> am i doing something wrong?

Using 'void' as the return type for main; using '%Lu' instead of '%llu' for
the specifier for unsigned long long.  Perhaps also: using an
implementation that incorrectly thinks unsigned long long can have only 32
bits; using a C90 compiler for which "long long" is not defined and for
which a return <value> statement or exit(<value>) call is needed.

You might note that "string" is a bit misleading in the output statement.



Fri, 20 May 2005 16:26:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. char size (was long long long long long int)

2. typecasting int to long long int

3. long long int into octets (and back again)

4. long long int

5. unsigned long long int

6. long long int

7. Assigning and printing long long int's

8. long long int

9. long long long long integers

10. long int versus long

11. Help! INT longer than LONG

12. Handling very large integers without "long long int"

 

 
Powered by phpBB® Forum Software