guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `SCM_MAKE_CHAR ()' signedness issue


From: Mike Gran
Subject: Re: `SCM_MAKE_CHAR ()' signedness issue
Date: Tue, 18 Aug 2009 11:54:55 -0700 (PDT)

> From: carlo.bramix <address@hidden>
> 
> Hello,
> unfortunately that code still fails into libguile/print.c
> Infact, a signed char just arrives to 127 and the " < 128" causes:
> 
> ../../guile-git/libguile/print.c:1101: warning: comparison is always true due 
> to 
> limited range of data type
> ../../guile-git/libguile/print.c:1108: warning: comparison is always true due 
> to 
> limited range of data type

Doh!  You're right.

> 
> But in this manner it seems ok:
> 
> #define SCM_MAKE_CHAR(x)                                              \
>   (((scm_t_int32) (x) + 128) < 128                                    \
>   ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)  \
>   : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))

Alternately, you could put in any number between 0 and 127, I think, and get 
the correct behavior.

#define SCM_MAKE_CHAR(x)                                              \
  ((x) < 64                                    \
  ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)  \
  : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))

-Mike





reply via email to

[Prev in Thread] Current Thread [Next in Thread]