Re: Language features and reinterpret casts

2010-11-01 Thread Bruno Medeiros
On 21/09/2010 09:23, Simen kjaeraas wrote: bearophile wrote: klickverbot: Are there any cases where (*cast(int*)&someFloat) does not fit the bill? I am not a C lawyer, but I think that too is undefined in C (and maybe D too). From your own link (http://www.digitalmars.com/webnews/newsgrou

Re: Language features and reinterpret casts

2010-11-01 Thread Bruno Medeiros
On 21/09/2010 00:27, bearophile wrote: klickverbot: Are there any cases where (*cast(int*)&someFloat) does not fit the bill? I am not a C lawyer, but I think that too is undefined in C (and maybe D too). Bye, bearophile In general, it is definitely undefined behavior in C, but that's becaus

Re: Language features and reinterpret casts

2010-09-21 Thread Jesse Phillips
I remember that thread and even replied to it. I didn't see anything where Walter said Unions behave as C. Nor was there anything where Walter said he would not define C undefined behavior. All he said was, for the cases presented, there was no way to define the behavior or didn't know what defi

Re: Language features and reinterpret casts

2010-09-21 Thread BCS
Hello Don, BCS wrote: Hello Don, How would that work? Can a system store ints big-endian and floats little-endian? Not sure. My limited understanding is that with on PowerPC, Altivec can use big-endian floats, even when the PPC is set to little-endian mode. Could be wrong, though. In any ca

Re: Language features and reinterpret casts

2010-09-21 Thread Don
BCS wrote: Hello Don, BCS wrote: Hello Don, It's going to be implementation defined behaviour (will depend on endianness) Does that matter if the members are the same size? Definitely -- you'll grab the part of the mantissa, instead of the exponent. How would that work? Can a system s

Re: Language features and reinterpret casts

2010-09-21 Thread BCS
Hello Don, BCS wrote: Hello Don, It's going to be implementation defined behaviour (will depend on endianness) Does that matter if the members are the same size? Definitely -- you'll grab the part of the mantissa, instead of the exponent. How would that work? Can a system store ints bi

Re: Language features and reinterpret casts

2010-09-21 Thread bearophile
Don: > It's going to be implementation defined behaviour (will depend on > endianness) but not undefined behaviour. > BTW std.math heavily relies on reinterpret casting float->int. I suggest to add something like a std.traits.ReinterpretCast template to Phobos and use only it in Phobos modules a

Re: Language features and reinterpret casts

2010-09-21 Thread Simen kjaeraas
bearophile wrote: klickverbot: Are there any cases where (*cast(int*)&someFloat) does not fit the bill? I am not a C lawyer, but I think that too is undefined in C (and maybe D too). From your own link (http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_

Re: Language features and reinterpret casts

2010-09-21 Thread Don
BCS wrote: Hello Don, BCS wrote: Hello bearophile, Jesse Phillips: Why not, define the behavior and leave it. This was the original purpose of my thread, but Walter has explained me that this is not possible for the unions: I don't see how those apply to unions. It's going to be imp

Re: Language features and reinterpret casts

2010-09-20 Thread BCS
Hello Don, BCS wrote: Hello bearophile, Jesse Phillips: Why not, define the behavior and leave it. This was the original purpose of my thread, but Walter has explained me that this is not possible for the unions: I don't see how those apply to unions. It's going to be implementation

Re: Language features and reinterpret casts

2010-09-20 Thread Don
BCS wrote: Hello bearophile, Jesse Phillips: Why not, define the behavior and leave it. This was the original purpose of my thread, but Walter has explained me that this is not possible for the unions: I don't see how those apply to unions. It's going to be implementation defined beha

Re: Language features and reinterpret casts

2010-09-20 Thread BCS
Hello bearophile, Jesse Phillips: Why not, define the behavior and leave it. This was the original purpose of my thread, but Walter has explained me that this is not possible for the unions: I don't see how those apply to unions. -- ... <

Re: Language features and reinterpret casts

2010-09-20 Thread bearophile
Jesse Phillips: > But where does Walter say Unions act as C in this case? It was an answer in a thread of mine where I have asked to remove some D undefined behaviours derived from C. This is the thread start: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=1

Re: Language features and reinterpret casts

2010-09-20 Thread Jonathan M Davis
On Monday, September 20, 2010 18:21:53 Jesse Phillips wrote: > bearophile Wrote: > > - C Standard says that assigning to one member of a union and then > > accessing a different member is undefined behaviour. - GCC is a > > practical compiler, so it has the -fno-strict-aliasing switch, that > > all

Re: Language features and reinterpret casts

2010-09-20 Thread Jesse Phillips
bearophile Wrote: > - C Standard says that assigning to one member of a union and then accessing > a different member is undefined behaviour. > - GCC is a practical compiler, so it has the -fno-strict-aliasing switch, > that allows to use that trick. See "-Wstrict-aliasing" and: > http://stackov

Re: Language features and reinterpret casts

2010-09-20 Thread bearophile
klickverbot: > Are there any cases where (*cast(int*)&someFloat) does not fit the bill? I am not a C lawyer, but I think that too is undefined in C (and maybe D too). Bye, bearophile

Re: Language features and reinterpret casts

2010-09-20 Thread klickverbot
On 9/20/10 11:52 PM, bearophile wrote: Recently Bradley Mitchell in D.learn newsgroup has tried to implement the Quake fast inverse square root algorithm in D, and has found D lack the C++ reinterpret cast: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_

Re: Language features and reinterpret casts

2010-09-20 Thread Adam D. Ruppe
On Mon, Sep 20, 2010 at 05:52:06PM -0400, bearophile wrote: > Recently Bradley Mitchell in D.learn newsgroup has tried to implement the > Quake fast inverse square root algorithm in D, and has found D lack the C++ > reinterpret cast: > http://www.digitalmars.com/webnews/newsgroups.php?art_group=d

Language features and reinterpret casts

2010-09-20 Thread bearophile
On Reddit I have read some people complain that D2 is a too much complex language because it has too many features. Feature "count" increases a language complexity, but most of the complexity comes from other sources, like unwanted interactions between features, messy feature semantics, unspecif