Implicit conversion C vs C#

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

I've recently faced the following problem.
Say, we have a function in C#.
void SomeFunction(float f)
{...}

Now, we want to call this function and write something like
SomeFunction(2/3);

I used the debugger and found out that this call is equivalent to
SomeFunction(0);

In another words, the system would take the two integer numbers, divide them
as integers, receive 0, convert to float and pass to the function.

If I remember well, C would work different. It would convert all the
arguments of the expression to the most informative type (float in this
case), calculate the result and pass it to the function.
Writing SomeFunction(2/3) in C is equivalent to
SomeFunction((float)2/(float)3) in C#.

Is it "by design", or a bug.
 
Back
Top