C++ Logo

SG12

Advanced search

Subject: Re: [ub] bit_cast
From: Chandler Carruth (chandlerc_at_[hidden])
Date: 2013-11-04 12:56:20


On Mon, Nov 4, 2013 at 10:42 AM, Gabriel Dos Reis <gdr_at_[hidden]> wrote:

> | -----Original Message-----
> | From: ub-bounces_at_[hidden] [mailto:ub-bounces_at_[hidden]] On
> Behalf Of
> | Lawrence Crowl
> | Sent: Monday, November 4, 2013 10:40 AM
> | To: WG21 UB study group
> | Subject: Re: [ub] bit_cast
> |
> | The intent is to provide an alternative to the idiom
> |
> | int i; float f = *(float*)&i;
> |
> | The usual objection is "but memcpy is slow".
> | The answer is "your compiler is better than you think".
>
> If we give it enough latitude in terms of non-aliasing :-)

The compiler needs no latitude to optimize using memcpy to do this.



SG12 list run by sg12-owner@lists.isocpp.org