guile-devel
[Top][All Lists]
Advanced

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

Fixing num2integral.i.c's warnings (a proposal).


From: Rob Browning
Subject: Fixing num2integral.i.c's warnings (a proposal).
Date: Wed, 19 Sep 2001 18:01:22 -0500
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

On some systems, some of the functions generated my num2integral.i.c
are going to generate warnings that can't be avoided with the current
approach.  That's because they have a test (see below) for
"sizeof(ITYPE) < sizeof(scm_t_signed_bits)" just before a
SCM_FIXABLE(n) test.

The problem is that since the sizeof tests can't be performed at
compile time, the compiler complains about the SCM_FIXABLE(n) test
always being true (which for say, ITYPE == short, it will be), and
aside from complaining, will also generate useless code.

So I was trying to figure out a better way to handle this, and here's
my first attempt.  Please shoot me down, or suggest better
alternatives as appropriate.

Since the compiler can't compute sizeof(X) at compile time and
automagically rewrite our conditional, I propose we fix up configure
to generate a set of variables of the form GUILE_SIZEOF_FOO where FOO
is one of the itypes, and also a variable named
GUILE_SIZEOF_SCM_T_SIGNED_BITS (feel free to suggest other names,
though these don't need to be public).

Then INTEGRAL2NUM can be rewritten to conditionally compile code based
on a test like this

  #if GUILE_SIZEOF_ITYPE < GUILE_SIZEOF_SCM_T_SIGNED_BITS
    ...

and just before #including num2integral.i.c, you'd just add an
appropriate "#define SIZEOF_ITYPE GUILE_SIZEOF_FOO" along with the
#define for ITYPE.

This would not only fix the warnings, but should remove some unused
code from some of the conversions.

Here's the code that I'm talking about:

  SCM
  INTEGRAL2NUM (ITYPE n)
  {
    if (sizeof (ITYPE) < sizeof (scm_t_signed_bits)
        ||
  #ifndef UNSIGNED  
        SCM_FIXABLE (n)
  #else
        SCM_POSFIXABLE (n)
  #endif 
        )
      return SCM_MAKINUM ((long) n);

  #ifdef SCM_BIGDIG
    return INTEGRAL2BIG (n);
  #else
    return scm_make_real ((double) n);
  #endif
  }

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C  64AE 78FE E5FE F0CB A0AD



reply via email to

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