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
Thanks. It's not that I'm worried about, I was only curious. :)
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(
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
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.)
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
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
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