Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > long long int and sscanf, printf

Reply
Thread Tools

long long int and sscanf, printf

 
 
Hans Vlems
Guest
Posts: n/a
 
      09-07-2012
I'm moving from the djgpp environment to mingw. This also implies a
more modern C compiler,
djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the
most current version but
that's what I have available right now).
The change resulted in one error and one I can't figure out.
A call to sscanf like sscanf(charptr,"%lld",&longlonginteger);
presented to problem for 4.4.4, neither syntactically nor in resulting
functionality. The compiler didn't complain and the code behaved as I
expected so no complaints.

However gcc 4.7.0 flags an error:

t2.c:6:3: warning: unknown conversion type character l in format [-
Wformat]
t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args]

The question is what conversion specification is required to read and
print long long int variables?
Hans

PS
The compiler errors are translated from Dutch so will very likely
differ from the original English messages
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      09-07-2012
On 9/7/2012 7:43 AM, Hans Vlems wrote:
> I'm moving from the djgpp environment to mingw. This also implies a
> more modern C compiler,
> djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the
> most current version but
> that's what I have available right now).
> The change resulted in one error and one I can't figure out.
> A call to sscanf like sscanf(charptr,"%lld",&longlonginteger);
> presented to problem for 4.4.4, neither syntactically nor in resulting
> functionality. The compiler didn't complain and the code behaved as I
> expected so no complaints.
>
> However gcc 4.7.0 flags an error:
>
> t2.c:6:3: warning: unknown conversion type character l in format [-
> Wformat]
> t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args]
>
> The question is what conversion specification is required to read and
> print long long int variables?


"%lld" is correct, for both printf() and scanf(). However,
`long long int' was introduced by the C99 standard, and wasn't
part of the original ANSI/C89/C90 version. Have you specified
which version of C gcc should compile? Try "-std=c99" on the
gcc command line, and see if that helps.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
"The speed at which the system fails is usually not important."
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-07-2012
Hans Vlems <(E-Mail Removed)> writes:

> I'm moving from the djgpp environment to mingw. This also implies a
> more modern C compiler,
> djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the
> most current version but
> that's what I have available right now).
> The change resulted in one error and one I can't figure out.
> A call to sscanf like sscanf(charptr,"%lld",&longlonginteger);
> presented to problem for 4.4.4, neither syntactically nor in resulting
> functionality. The compiler didn't complain and the code behaved as I
> expected so no complaints.
>
> However gcc 4.7.0 flags an error:
>
> t2.c:6:3: warning: unknown conversion type character l in format [-
> Wformat]
> t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args]
>
> The question is what conversion specification is required to read and
> print long long int variables?


%lld is correct. The only way I can get close to reproducing this error
is to compiler with -std=c90 -pedantic but then I get a very clear
message the C90 does not support 'll'. This is gcc 4.6.3, though.

On a similar issue (though probably not connected to this particular
problem) I was under the impression that mingw used a native Windows C
library and because, at the time, MS did not support C99, printing long
long ints did not work property. That may all be different now, for one
thing I think MS C compilers understand long long now, but it's worth
checking.

--
Ben.
 
Reply With Quote
 
John Coleman
Guest
Posts: n/a
 
      09-07-2012
On Friday, September 7, 2012 7:43:15 AM UTC-4, Hans Vlems wrote:
> I'm moving from the djgpp environment to mingw. This also implies a more modern C compiler, djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the most current version but that's what I have available right now). The change resulted in one error and one I can't figure out. A call to sscanf like sscanf(charptr,"%lld",&longlonginteger); presented to problem for 4.4.4, neither syntactically nor in resulting functionality. The compilerdidn't complain and the code behaved as I expected so no complaints. However gcc 4.7.0 flags an error: t2.c:6:3: warning: unknown conversion type character l in format [- Wformat] t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args] The question is what conversion specification isrequired to read and print long long int variables? Hans PS The compiler errors are translated from Dutch so will very likely differ from the original English messages


gcc in mingw uses Microsoft's implementation of C's standard library, whichdoesn't support C99 extensions. Thus gcc in mingw doesn't implement changes that C99 made to the standard library. You'll have to find a work-around (e.g. split a long-long into two longs and print them successively)
 
Reply With Quote
 
ImpalerCore
Guest
Posts: n/a
 
      09-07-2012
On Sep 7, 7:43*am, Hans Vlems <(E-Mail Removed)> wrote:
> I'm moving from the djgpp environment to mingw. This also implies a
> more modern C compiler,
> djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the
> most current version but
> that's what I have available right now).
> The change resulted in one error and one I can't figure out.
> A call to sscanf like sscanf(charptr,"%lld",&longlonginteger);
> presented to problem for 4.4.4, neither syntactically nor in resulting
> functionality. The compiler didn't complain and the code behaved as I
> expected so no complaints.
>
> However gcc 4.7.0 flags an error:
>
> t2.c:6:3: warning: unknown conversion type character l in format [-
> Wformat]
> t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args]
>
> The question is what conversion specification is required to read and
> print long long int variables?
> Hans
>
> PS
> The compiler errors are translated from Dutch so will very likely
> differ from the original English messages


MinGW uses the C Runtime, which has limited C99 support. I have my
own <stdint.h> wrapper that takes Microsoft's quirks into
consideration. There's a few ways to work around it, but I found that
adding a custom fprintf modifier was the cleanest.

\code
/*
* The Microsoft Runtime library is notorious for using its own
* custom fprintf modifier prefix for 64-bit integers.
*/
#if defined(__STDC__) && defined(__STDC_VERSION__)
# if (__STDC__ && __STDC_VERSION__ >= 199901L)
# define inttypes_pridlonglong_defined
# if defined(_WIN32) || defined(__WIN32__)
# define PRIdLL "I64d"
# define PRIiLL "I64i"
# define PRIoLL "I64o"
# define PRIuLL "I64u"
# define PRIxLL "I64x"
# define PRIXLL "I64X"
# else
# define PRIdLL "lld"
# define PRIiLL "lli"
# define PRIoLL "llo"
# define PRIuLL "llu"
# define PRIxLL "llx"
# define PRIXLL "llX"
# endif
# endif
#endif
\endcode

Then you just use it like the rest of the <inttypes.h> fprintf
modifiers.

printf( "longlongint = %" PRIdLL "\n", longlongint );

The corresponding SCN versions are left as an exercise. If using
reserved names worries you, add a prefix.

Best regards,
John D.
 
Reply With Quote
 
Hans Vlems
Guest
Posts: n/a
 
      09-07-2012
On 7 sep, 15:38, ImpalerCore <(E-Mail Removed)> wrote:
> On Sep 7, 7:43*am, Hans Vlems <(E-Mail Removed)> wrote:
>
>
>
>
>
> > I'm moving from the djgpp environment to mingw. This also implies a
> > more modern C compiler,
> > djgpp supports gcc 4.4.4 and mingw uses gcc 4.7.0 (possibly not the
> > most current version but
> > that's what I have available right now).
> > The change resulted in one error and one I can't figure out.
> > A call to sscanf like sscanf(charptr,"%lld",&longlonginteger);
> > presented to problem for 4.4.4, neither syntactically nor in resulting
> > functionality. The compiler didn't complain and the code behaved as I
> > expected so no complaints.

>
> > However gcc 4.7.0 flags an error:

>
> > t2.c:6:3: warning: unknown conversion type character l in format [-
> > Wformat]
> > t2.c:6:3: warning: too many arguments for format [-Wformat-extra-args]

>
> > The question is what conversion specification is required to read and
> > print long long int variables?
> > Hans

>
> > PS
> > The compiler errors are translated from Dutch so will very likely
> > differ from the original English messages

>
> MinGW uses the C Runtime, which has limited C99 support. *I have my
> own <stdint.h> wrapper that takes Microsoft's quirks into
> consideration. *There's a few ways to work around it, but I found that
> adding a custom fprintf modifier was the cleanest.
>
> \code
> /*
> ** The Microsoft Runtime library is notorious for using its own
> ** custom fprintf modifier prefix for 64-bit integers.
> **/
> #if defined(__STDC__) && defined(__STDC_VERSION__)
> # *if (__STDC__ && __STDC_VERSION__ >= 199901L)
> # * *define inttypes_pridlonglong_defined
> # * *if defined(_WIN32) || defined(__WIN32__)
> # * * *define PRIdLL *"I64d"
> # * * *define PRIiLL *"I64i"
> # * * *define PRIoLL *"I64o"
> # * * *define PRIuLL *"I64u"
> # * * *define PRIxLL *"I64x"
> # * * *define PRIXLL *"I64X"
> # * *else
> # * * *define PRIdLL *"lld"
> # * * *define PRIiLL *"lli"
> # * * *define PRIoLL *"llo"
> # * * *define PRIuLL *"llu"
> # * * *define PRIxLL *"llx"
> # * * *define PRIXLL *"llX"
> # * *endif
> # *endif
> #endif
> \endcode
>
> Then you just use it like the rest of the <inttypes.h> fprintf
> modifiers.
>
> printf( "longlongint = %" PRIdLL "\n", longlongint );
>
> The corresponding SCN versions are left as an exercise. *If using
> reserved names worries you, add a prefix.
>
> Best regards,
> John D.- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


Thank you all for your comments,
I use King's book (C Programming) as reference
and noted that the ll length specifier is C99 specific. The fact that
a newer
version of gcc flagged an error was somewhat of a surprise. The
explanation is
clear and quite obvious (a hindsight attribute .
Thanks for the workaround John!
Hans
 
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
Promoting unsigned long int to long int pereges C Programming 112 07-28-2008 05:00 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
printf / sscanf unsigned long long int variables Joerg Schwerdtfeger C Programming 3 04-02-2004 07:03 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments