unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* SCM_POSFIXABLE(-1) fails with MSVC++ 6.0
@ 2002-08-22 13:30 Lars J. Aas
  2002-08-22 13:47 ` Lars J. Aas
  0 siblings, 1 reply; 7+ messages in thread
From: Lars J. Aas @ 2002-08-22 13:30 UTC (permalink / raw)


  Hi guys,

I've been compiling Guile 1.5.6 with MSVC++ on Cygwin.
Today I found a strange bug in my modified version, that
made this test fail:

  (if (= ( { scm_long2num(-1) } ) -1)
      (display "there is no bug\n")
      (display "there is a bug!\n"))

I tracked the problem down to SCM_POSFIXABLE(-1) failing
with MSVC++, causing scm_long2num(-1) to create a bignum
instead of an integer, but succeeding on GNU/Linux w/gcc.
I don't see immediately why it should happen - it looks
like a compiler bug to me.

Here is a fairly minimal example.  If anyone has access to
MSVC++ and can understand why it fails and how to correct
the SCM_POSFIXABLE macro to work with MSVC++, it would be
very nice, and ought to go into the Guile sources too.

  Lars J


#include <stdio.h>
#include <limits.h>

typedef signed long scm_t_signed_bits;

#ifdef CHAR_BIT
# define SCM_CHAR_BIT CHAR_BIT
#else
# define SCM_CHAR_BIT 8
#endif

#ifdef LONG_BIT
# define SCM_LONG_BIT LONG_BIT
#else
# define SCM_LONG_BIT (SCM_CHAR_BIT * sizeof (long) / sizeof (char))
#endif

#define SCM_I_FIXNUM_BIT \
  (SCM_LONG_BIT - 2)

#define SCM_MOST_POSITIVE_FIXNUM \
  ((((scm_t_signed_bits) 1) << (SCM_I_FIXNUM_BIT - 1)) - 1)

#define SCM_POSFIXABLE(n) ((n) <= SCM_MOST_POSITIVE_FIXNUM)

int
main(int argc, char ** argv)
{
  fprintf(stderr, "testing through SCM_POSFIXABLE if -1 is <= %ld - ", SCM_MOST_POSITIVE_FIXNUM);
  if ( SCM_POSFIXABLE(-1) ) fprintf(stderr, "true\n");
  else                      fprintf(stderr, "not so!\n");

  fprintf(stderr, "testing directly if -1 is <= %ld - ", SCM_MOST_POSITIVE_FIXNUM);
  if ( -1 <= 536870911 ) fprintf(stderr, "true\n");
  else                   fprintf(stderr, "not so!\n");

  return 0;
}



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-08-25 16:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2002-08-25 16:01         ` Lynn Winebarger

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).