[Bug c/20445] New: garbage returned when trying to get the second word of a double value

2005-03-12 Thread sumii at saul dot cis dot upenn dot edu
 gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparcv9-sun-solaris2/3.3.2/specs
Configured with: /usr/local/src/gnu/gcc-3.3.2/configure --enable-languages=c,c+¥
+ sparcv9-sun-solaris2
Thread model: posix
gcc version 3.3.2
 cat test.c
#include stdio.h

typedef int int32;

void out(int32 i) {
  printf(0x%x¥n, i);
}

double inp(void) {
  return 123.456789;
}

void getlo() {
  double d = inp();
  int32 i = *((int32 *)d + 1);
  out(i);
}

void gethi() {
  double d = inp();
  int32 i = *(int32 *)d;
  out(i);
}

int main() {
  gethi();
  getlo();
  return 0;
}
 gcc -m32 -O2 test.c -o test
 ./test
0x405edd3c
0xfbbb3834
 gcc -m32 -O test.c -o test
 ./test
0x405edd3c
0x7ee0b0b

-- 
   Summary: garbage returned when trying to get the second word of a
double value
   Product: gcc
   Version: 3.3.2
Status: UNCONFIRMED
  Severity: critical
  Priority: P2
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sumii at saul dot cis dot upenn dot edu
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparcv9-sun-solaris2
  GCC host triplet: sparcv9-sun-solaris2
GCC target triplet: sparcv9-sun-solaris2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20445


[Bug c/20445] garbage returned when trying to get the second word of a double value

2005-03-12 Thread sumii at saul dot cis dot upenn dot edu

--- Additional Comments From sumii at saul dot cis dot upenn dot edu  
2005-03-12 21:40 ---
(In reply to comment #1)
 You are violating C aliasing rules, try an union.  Read
http://gcc.gnu.org/bugs.html which show how to 
 deal with this.

Oops, my double stupidity (forgetting the ISO rule _and_ overlooking the FAQ
entry)...  Apology for bothering you.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20445