From: "Lars J. Aas" <larsa@sim.no>
Cc: Guile Devel <guile-devel@gnu.org>
Subject: Re: SCM_POSFIXABLE(-1) fails with MSVC++ 6.0
Date: Sun, 25 Aug 2002 15:27:27 +0200 [thread overview]
Message-ID: <20020825132727.GB22670@sim.no> (raw)
In-Reply-To: <Pine.GSO.4.05.10208240941200.4796-100000@sallust.ida.ing.tu-bs.de>
Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> wrote:
: On Fri, 23 Aug 2002, Lars J. Aas wrote:
:
: > Lars J. Aas <larsa@sim.no> 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
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2002-08-25 13:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-22 13:30 SCM_POSFIXABLE(-1) fails with MSVC++ 6.0 Lars J. Aas
2002-08-22 13:47 ` Lars J. Aas
2002-08-23 10:40 ` Lars J. Aas
2002-08-24 7:42 ` Dirk Herrmann
2002-08-24 15:57 ` Lynn Winebarger
2002-08-25 13:27 ` Lars J. Aas [this message]
2002-08-25 16:01 ` Lynn Winebarger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020825132727.GB22670@sim.no \
--to=larsa@sim.no \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).