guile-devel
[Top][All Lists]
Advanced

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

Re: SCM_POSFIXABLE(-1) fails with MSVC++ 6.0


From: Lars J. Aas
Subject: Re: SCM_POSFIXABLE(-1) fails with MSVC++ 6.0
Date: Sun, 25 Aug 2002 15:27:27 +0200
User-agent: Mutt/1.3.24i

Dirk Herrmann <address@hidden> wrote:
: On Fri, 23 Aug 2002, Lars J. Aas wrote:
: 
: > Lars J. Aas <address@hidden> wrote:
: > : Changing the alternative definition of SCM_LONG_BITS to cast the value
: > : to long like this works...
: > : 
: > : # define SCM_LONG_BIT ((long)(SCM_CHAR_BIT * sizeof (long) / sizeof 
(char)))
: > 
: > Come to think of it, the cast is better placed on the inside so it's more
: > evident what is being done (stopping the unsigned-ness of the sizeof()-
: > operations to propagate incorrectly out through the macro invokation) so
: > it's not removed later by someone not knowing about this compiler bug.
: > 
: > # define SCM_LONG_BIT (SCM_CHAR_BIT * ((long) (sizeof (long) / sizeof 
(char))))
: > 
: > or s/long/int/ on the cast?
: > 
: > BTW, is anyone reading these mails? ;)
: > 
: >   Lars J
: 
: I am not sure I understand the problem here:  is the failure of testing 
: -1 <= sizeof(long) a compiler bug, or is the strange behaviour defined
: in the C language?

I haven't studied the C specification under a microscope, but it has got
to be a compiler bug.  What I guess is happening is that sizeof() is defined
to return an unsigned value, and consequently -1 is interpreted as an unsigned
value.  Exactly how data type qualifiers are supposed to propagate over unary
tests isn't something I know for sure, but gcc handles it as one would expect.

BTW, I don't think the define makes sense at all.  I believe it's part of
the C standard that sizeof(char) should always return 1, whether the char type
is the size of a byte or not.  Besides, if it had returned the number of bytes
a char is - why would one want to divide by it?  Multiply perhaps, but that
would only be if sizeof(long) returned the number of _chars_ in a long, and
sizeof(char) returned the number of _bytes_ in a char, which wouldn't make
sense either.  So there's some stuff I think is wrong there, but I guess that
part of the #if/else isn't that often used, and when it's used, it doesn't
affect the result since it's a divide-by-one thing and char is always a byte
long.

I propose that the define is changed to:

# define SCM_LONG_BIT (SCM_CHAR_BIT * ((int) sizeof(long)))

  Lars J




reply via email to

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