This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: sscanf() problems
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: newlib at sourceware dot org
- Date: Tue, 2 Dec 2014 19:02:19 -0500 (EST)
- Subject: Re: sscanf() problems
- Authentication-results: sourceware.org; auth=none
- References: <547DA0B0 dot 1070707 at weiss-robotics dot de> <134867476 dot 16062418 dot 1417552087594 dot JavaMail dot zimbra at redhat dot com> <1417558948473 dot 17646 at LGSInnovations dot com>
IMO, the correct thing to do is to alter the header file, but to do so
without a warning. A comment should be added and noted that the library
will ignore the macros if it has not been configured properly. The users that
actually have a problem will get an error and have a way to find out why.
-- Jeff J.
----- Original Message -----
> From: "Craig D Howland" <howland@LGSInnovations.com>
> To: newlib@sourceware.org
> Sent: Tuesday, December 2, 2014 5:22:28 PM
> Subject: RE: sscanf() problems
>
> Jeff:
>
> This sounds plausible, but then is also a bug: the SCN*8 defines in
> inttypes.h should not be defined when _WANT_IO_C99_FORMATS is not. This
> would provide a compilation error for the given test case. A #warning in
> inttypes.h might be appropriate. (The C99 standard does explicitly call for
> the corresponding macros to not be defined if fscanf does not have a
> suitable length modifier for the type.)
>
> For that matter, however, inttypes.h was added for C99, so an argument could
> be made that the entire file really should not be used if
> _WANT_IO_C99_FORMATS has not been defined. In which case inttypes.h should
> have a #error.
>
> So, for example something along these lines:
>
> Case 1, altered inttypes.h
> #if !defined(_WANT_IO_C99_FORMATS)
> #warning "inttypes.h is not entirely safe to use when _WANT_IO_C99_FORMATS
> is not defined"
> #else
> // define the SCN*8 stuff
> #endif
>
> or
>
> Case 2, no inttypes.h
> #if !defined(_WANT_IO_C99_FORMATS)
> #error "inttypes.h must not be used when not full C99"
> #endif
>
> Thoughts on which approach is better? The first choice is major approach, for
> either no or altered inttypes.h. If altered, there's a question as to having
> a #warning or not. The warning would be spurious for people not using SCN*8.
> People using SCN*8 will find out when compilation fails with or without a
> #warning, but the #warning would give them an immediate clue as to why.
>
> Craig
> ________________________________________
> From: newlib-owner@sourceware.org <newlib-owner@sourceware.org> on behalf of
> Jeff Johnston <jjohnstn@redhat.com>
> Sent: Tuesday, December 2, 2014 3:28 PM
> To: Steffen Wolfer
> Cc: newlib@sourceware.org
> Subject: Re: sscanf() problems
>
> I believe I know what is happening.
>
> The SCNu8 macro expands to be hhu
>
> The vfscanf.c code only supports hh if the flag _WANT_IO_C99_FORMATS is set
> to true. By default it is false in newlib/configure.host and for a few
> select
> platforms, it is set to true.
>
> If you did not configure your library with --enable-newlib-io-c99-formats,
> then
> it is false as arm doesn't set it to true.
>
> ...
>
> -- Jeff J.
>
> ----- Original Message -----
> > From: "Steffen Wolfer" <wolfer@weiss-robotics.de>
> > To: newlib@sourceware.org
> > Sent: Tuesday, December 2, 2014 6:21:20 AM
> > Subject: sscanf() problems
> >
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Dear all,
> >
> > I'm having the following, interesting problem using Newlib's sscanf().
> > ...
> >
> >
> > Thanks,
> > Steffen
>
>