[plt-scheme] miscaellanous packaging problems with plt-scheme

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Aug 11 00:35:28 EDT 2004

I finally got back to the gcc 3.4.1 problem, and I can confirm that
MzScheme doesn't build correctly.

The problem is illustrated by the little program below:

 Compiler   Optimization    Printout
 gcc 3.2.2                   0 1
 gcc 3.2.2    -O2            0 1
 gcc 3.4.1                   0 1
 gcc 3.4.1    -O2            0 0    <------ different

The intent of the code, of course, is to compare a pair of doubles
byte-by-byte. It's possible that I still misunderstand aliasing in C99,
so if anyone knows what I've done wrong and/or how I should write this
to get the intended result, please let me know. (In MzScheme, I
actually want to detect -0.0, so I would be nearly as happy to learn
about a library function that will detect negative zero for me.)

Removing the "inline" declaration makes gcc 3.4.1 with -O2 behave like
the other cases. I think I may have had the "inline" disabled in v207,
which would explain the v207 versus v208 difference.



#include <stdio.h>

double zero = 0.0;

inline int zero_p(double d)
  /* Relies on 4-byte "int": */
  if (((int *)(char *)&d)[0] == ((int *)(char *)&zero)[0]
      && ((int *)(char *)&d)[1] == ((int *)(char *)&zero)[1])
    return 1;

  return 0;

int x_zero_p(double d)
  return zero_p(d);

int main()
  printf("%d\n", x_zero_p(17.0));
  printf("%d\n", x_zero_p(0.0));
  return 0;

Posted on the users mailing list.