User account creation filtered due to spam.

Bug 29991 - double: conversion to bits
Summary: double: conversion to bits
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2006-11-27 09:00 UTC by Hans Buchmann
Modified: 2006-11-27 09:51 UTC (History)
7 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Hans Buchmann 2006-11-27 09:00:08 UTC
Compiling the Code

#include <iostream>
#include <iomanip>
typedef long long unsigned Significant;

Significant conv(double v)
 return *(Significant*)&v;

double v=1.0;
int main(unsigned argc,char* args[])

with -O1 gives the correct result:


however compiling the same code with -O2 gives (for example):


The assembler output:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp        ;dont read the value form stack
	movl	-8(%ebp), %eax
	movl	-4(%ebp), %edx

Output of:
 g++ -v

Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.1/work/gcc-4.1.1/configure 
Thread model: posix
gcc version 4.1.1 (Gentoo 4.1.1)

Best regards

Hans Buchmann
Comment 1 Pawel Sikora 2006-11-27 09:07:15 UTC
did you ever read the gcc warnings? `-Wall' tells you what's wrong.
use -fno-strict-aliasing or memcpy() for such conversions.
Comment 2 Andreas Schwab 2006-11-27 09:51:33 UTC

*** This bug has been marked as a duplicate of 21920 ***