long long int and sscanf, printf

H

Hans Vlems

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
 
E

Eric Sosman

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.
 
B

Ben Bacarisse

Hans Vlems said:
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.
 
J

John Coleman

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)
 
I

ImpalerCore

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.
 
H

Hans Vlems

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top