guile-devel
[Top][All Lists]
Advanced

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

Re: gcc optimisation breaks guile floating point


From: Gary Houston
Subject: Re: gcc optimisation breaks guile floating point
Date: 3 Oct 2002 00:34:09 +0100

> Cc: address@hidden, address@hidden, address@hidden
> From: Marius Vollmer <address@hidden>
> Date: 03 Oct 2002 00:40:24 +0200
> 
> Gary Houston <address@hidden> writes:
> 
> > > Under gcc, the following statement:
> > > 
> > >   asm volatile ("" : : : "memory");
> > >
> > > [...]
> >
> > This is good, it's similar to a previous work-around in libguile/throw.c.
> 
> I haven't checked with the standard, but it might be the case that a
> compiler must assume that a pointer to char can alias any type.  Thus, 
> 
>   #define SCM_REAL_VALUE(x) (((scm_t_double *)((char *)SCM2PTR (x)))->real)
> 
> might work as well.

I tried the extra cast on the simple test case, but it doesn't help.
In ANSI C any such assumption would be for void *, not char *, but
the pointer was void * already.

#include <stdlib.h>
#include <string.h>

static void * make_z (double x)
{
  void *z = malloc (50);

  memset (z, 0, 50);
  *((unsigned long *) z) = 0;
  *((double *) z) = x;
  return z;
}

main ()
{
  void *z = make_z (3.2);
  double d = *((double *) z);
  int i;

  for (i = 0; i < sizeof (double); i++)
    {
      printf ("%d\n", ((unsigned char *) &d)[i]);
    }
  return 0;
}






reply via email to

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