You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Christopher Collins <cc...@apache.org> on 2016/03/07 21:55:37 UTC
Re: incubator-mynewt-larva git commit: MYNEWT-230
I realize I'm being annoying and pedantic, but I just wanted to clarify
the issue. The problem is a difference in standard libraries:
* baselibc: isdigit() is a function.
* newlib: isdigit() is a macro.
There is no problem when baselibc is used, because the argument gets
promoted to an integer as required by the C standard. With newlibc, no promotion occurs because macro invocations just translate to token substitution.
Normally this wouldn't be a problem either, but gcc can be configured to
raise an odd warning when a char is used to index an array
(-Wchar-subscripts). I am really not sure of the rationale for this
warning...
Chris
On Mon, Mar 07, 2016 at 08:12:44PM +0000, wes3@apache.org wrote:
> Repository: incubator-mynewt-larva
> Updated Branches:
> refs/heads/master db0e97b1e -> faa7814db
>
>
> MYNEWT-230
>
> explictely cast to an integer since some compilers don't like to implicitelty
> cast a char to an int
>
>
> Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
> Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/faa7814d
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/faa7814d
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/faa7814d
>
> Branch: refs/heads/master
> Commit: faa7814db73f712ffa46cf4522c22b821e32cce7
> Parents: db0e97b
> Author: Paul Dietrich <pa...@yahoo.com>
> Authored: Thu Mar 3 17:11:13 2016 -0800
> Committer: wes3 <wi...@micosa.io>
> Committed: Mon Mar 7 11:53:13 2016 -0800
>
> ----------------------------------------------------------------------
> libs/util/src/datetime.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/faa7814d/libs/util/src/datetime.c
> ----------------------------------------------------------------------
> diff --git a/libs/util/src/datetime.c b/libs/util/src/datetime.c
> index 902eb55..fe4fb38 100644
> --- a/libs/util/src/datetime.c
> +++ b/libs/util/src/datetime.c
> @@ -211,7 +211,7 @@ parse_number(const char *str, int digits, int *val)
> cp = str;
> end = str + digits;
> while (cp < end) {
> - if (!isdigit(*cp)) {
> + if (!isdigit((int) *cp)) {
> return (NULL);
> }
> *val *= 10;
> @@ -277,7 +277,7 @@ parse_datetime(const char *input, struct os_timeval *tv, struct os_timezone *tz)
> /* parse fractional seconds if specified */
> if (*cp == '.') {
> ep = ++cp;
> - while (isdigit(*ep)) {
> + while (isdigit((int) *ep)) {
> ep++;
> }
> digits = ep - cp;
>
Re: incubator-mynewt-larva git commit: MYNEWT-230
Posted by Neel Natu <ne...@runtime.io>.
On Mon, Mar 7, 2016 at 12:55 PM, Christopher Collins <cc...@apache.org>
wrote:
> I realize I'm being annoying and pedantic, but I just wanted to clarify
> the issue. The problem is a difference in standard libraries:
> * baselibc: isdigit() is a function.
> * newlib: isdigit() is a macro.
>
> There is no problem when baselibc is used, because the argument gets
> promoted to an integer as required by the C standard. With newlibc, no
> promotion occurs because macro invocations just translate to token
> substitution.
>
> Normally this wouldn't be a problem either, but gcc can be configured to
> raise an odd warning when a char is used to index an array
> (-Wchar-subscripts). I am really not sure of the rationale for this
> warning...
>
>
The rationale is that 'char' can be signed or unsigned depending on the
architecture. If a particular architecture has signed chars then integer
promotion can result in negative values (which most likely was not
intended).
There is a more detailed explanation in the following thread:
https://sourceware.org/ml/newlib/2010/msg00245.html
best
Neel
> Chris
>
>
> On Mon, Mar 07, 2016 at 08:12:44PM +0000, wes3@apache.org wrote:
> > Repository: incubator-mynewt-larva
> > Updated Branches:
> > refs/heads/master db0e97b1e -> faa7814db
> >
> >
> > MYNEWT-230
> >
> > explictely cast to an integer since some compilers don't like to
> implicitelty
> > cast a char to an int
> >
> >
> > Project:
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
> > Commit:
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/faa7814d
> > Tree:
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/faa7814d
> > Diff:
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/faa7814d
> >
> > Branch: refs/heads/master
> > Commit: faa7814db73f712ffa46cf4522c22b821e32cce7
> > Parents: db0e97b
> > Author: Paul Dietrich <pa...@yahoo.com>
> > Authored: Thu Mar 3 17:11:13 2016 -0800
> > Committer: wes3 <wi...@micosa.io>
> > Committed: Mon Mar 7 11:53:13 2016 -0800
> >
> > ----------------------------------------------------------------------
> > libs/util/src/datetime.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/faa7814d/libs/util/src/datetime.c
> > ----------------------------------------------------------------------
> > diff --git a/libs/util/src/datetime.c b/libs/util/src/datetime.c
> > index 902eb55..fe4fb38 100644
> > --- a/libs/util/src/datetime.c
> > +++ b/libs/util/src/datetime.c
> > @@ -211,7 +211,7 @@ parse_number(const char *str, int digits, int *val)
> > cp = str;
> > end = str + digits;
> > while (cp < end) {
> > - if (!isdigit(*cp)) {
> > + if (!isdigit((int) *cp)) {
> > return (NULL);
> > }
> > *val *= 10;
> > @@ -277,7 +277,7 @@ parse_datetime(const char *input, struct os_timeval
> *tv, struct os_timezone *tz)
> > /* parse fractional seconds if specified */
> > if (*cp == '.') {
> > ep = ++cp;
> > - while (isdigit(*ep)) {
> > + while (isdigit((int) *ep)) {
> > ep++;
> > }
> > digits = ep - cp;
> >
>