Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > format specifier for long long ints....

Reply
Thread Tools

format specifier for long long ints....

 
 
Ray Dillinger
Guest
Posts: n/a
 
      03-26-2006

Hi.

I'm using GCC on a SuSE Linux distribution, and the following program
doesn't work the way I expect. I'm using the conversion specifier for
long long integers that's in the man pages, but what's coming out is
interpreting the lowest few bytes of the long long int as an ordinary
integer. Other tests reveal that the full width is being preserved and
used in calculations - it's just output that seems broken. I must have
some misconfiguration somewhere, but I can't figure out what it is.
Has anyone else run up against this? Does anyone know how to fix it?

Thanks in advance,
Ray


#include <stdio.h>
main()
{
long long int foo = 10000000001LL;
printf("%lld\n", foo);
}

 
Reply With Quote
 
 
 
 
Jordan Abel
Guest
Posts: n/a
 
      03-26-2006
On 2006-03-26, Ray Dillinger <(E-Mail Removed)> wrote:
>
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken.


Your version of glibc does not support this conversion specifier. You
need to upgrade.
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      03-26-2006
Ray Dillinger wrote:
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken. I must have
> some misconfiguration somewhere, but I can't figure out what it is.
> Has anyone else run up against this? Does anyone know how to fix it?
>
> Thanks in advance,
> Ray
>
>
> #include <stdio.h>
> main()
> {
> long long int foo = 10000000001LL;
> printf("%lld\n", foo);
> }


This is probably a issue of your C library (glibc?). Upgrade to your
latest gcc and C library version and try agian. Your code is correct,
(though not strictly C99 conforming), and should produce the expected
output with a C99 compliant compiler and standard library.

 
Reply With Quote
 
Cesar Rabak
Guest
Posts: n/a
 
      03-27-2006
Ray Dillinger escreveu:
>
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken. I must have
> some misconfiguration somewhere, but I can't figure out what it is.
> Has anyone else run up against this? Does anyone know how to fix it?
>
> Thanks in advance,
> Ray
>
>
> #include <stdio.h>
> main()
> {
> long long int foo = 10000000001LL;
> printf("%lld\n", foo);
> }
>

In a Mandriva 2006 Linux with gcc 4.0.3 your code compiled gives:
$ ./a.out
10000000001

which I believe is what you expect.

As a double check, I attempted:

$ gcc-3.3.6 -o a-3.3.6 suse.c
$ ./a-3.3.6
10000000001
$ gcc-2.96 -o a-2.96 suse.c
$ ./a-2.96
10000000001

where gcc-?-? are respective older versions.

HTH

--
Cesar Rabak


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-27-2006
Cesar Rabak <(E-Mail Removed)> writes:
> Ray Dillinger escreveu:

[...]
>> #include <stdio.h>
>> main()
>> {
>> long long int foo = 10000000001LL;
>> printf("%lld\n", foo); }
>>

> In a Mandriva 2006 Linux with gcc 4.0.3 your code compiled gives:
> $ ./a.out
> 10000000001
>
> which I believe is what you expect.
>
> As a double check, I attempted:
>
> $ gcc-3.3.6 -o a-3.3.6 suse.c
> $ ./a-3.3.6
> 10000000001
> $ gcc-2.96 -o a-2.96 suse.c
> $ ./a-2.96
> 10000000001
>
> where gcc-?-? are respective older versions.


gcc is a compiler, not a complete implementation. It typically uses
whatever runtime library is provided by the OS. On Linux, that's
generally glibc; on other systems, it's likely to be something else.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange use of format specifier in printf Money C Programming 18 06-24-2006 05:37 AM
Does wrong format specifier leads to memory corruption? indushekara C Programming 4 06-22-2005 07:56 PM
limiting string size in data grid format specifier for column =?Utf-8?B?UGF1bA==?= ASP .Net 1 02-01-2005 12:47 AM
Struggling with struct.unpack() and "p" format specifier Geoffrey Python 5 12-01-2004 02:20 PM
format specifier Ravi Uday C Programming 2 07-16-2003 09:24 AM



Advertisments