Re: unnecessary casts

2013-01-31 Thread monarch_dodra
On Thursday, 31 January 2013 at 00:03:43 UTC, Timon Gehr wrote: On 01/30/2013 11:49 PM, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? ... Well, 'unnecessary casts' are a no-op anyway. (Yes, afaik DMD will even eliminate them from the AST.) There i

Re: unnecessary casts

2013-01-31 Thread Namespace
Thanks. It's not that I'm worried about, I was only curious. :)

Re: unnecessary casts

2013-01-30 Thread n00b
Le 30/01/2013 17:49, Namespace a écrit : Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? E.g. [code] void foo(T)(T num) { int f = cast(int) num; // ... } foo(42); // cast is unnecessary foo(4.2); // cast is necessary [/code] Or should I wrote everytime [code] void foo(

Re: unnecessary casts

2013-01-30 Thread bearophile
Namespace: I'm talking about exactly these kind of casts. See my example. I don't understand what you are trying to minimize. In both versions of your foo function you have 1 cast, so you aren't minimizing the number of casts you are writing in the code. Bye, bearophile

Re: unnecessary casts

2013-01-30 Thread Timon Gehr
On 01/30/2013 11:49 PM, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? ... Well, 'unnecessary casts' are a no-op anyway. (Yes, afaik DMD will even eliminate them from the AST.)

Re: unnecessary casts

2013-01-30 Thread Jonathan M Davis
On Wednesday, January 30, 2013 23:49:00 Namespace wrote: > Is the compiler (dmd) fit enough to detect and avoid unnecessary > casts? > > E.g. > [code] > void foo(T)(T num) { > int f = cast(int) num; > // ... > } > > foo(42); // cast is unnecessary > foo(4.2); // cast is necessary > [/code] > > O

Re: unnecessary casts

2013-01-30 Thread Namespace
On Wednesday, 30 January 2013 at 22:57:39 UTC, bearophile wrote: On Wednesday, 30 January 2013 at 22:49:01 UTC, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? I think the most important casts most worth avoiding are the ones you write in the code (bec

Re: unnecessary casts

2013-01-30 Thread bearophile
On Wednesday, 30 January 2013 at 22:49:01 UTC, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? I think the most important casts most worth avoiding are the ones you write in the code (because they are a source of bugs), not the ones the compiler perfor