• Welcome to Valhalla Legends Archive.
 

C++ to C# something is backwards?

Started by Fr0z3N, July 12, 2004, 12:06 PM

Previous topic - Next topic

Fr0z3N

it's like:

(Variable + 6) = Array[5];

how the hell would that convert to C#? It's like backwards C++.

Variable = (Array[5] + 6); would make more sence.

Eibro

Quote from: Rubicon on July 12, 2004, 12:06 PM
it's like:

(Variable + 6) = Array[5];

how the hell would that convert to C#? It's like backwards C++.

Variable = (Array[5] + 6); would make more sence.
No, those two aren't equivalent. The only way I see the first being a valid statement is if it were *(Variable + 6) = Array[5];, since (Variable + 6) isn't an l-value and thus cannot be assigned to.
Eibro of Yeti Lovers.

Yoni

Surely you can see the statement being valid. Just overload operator+ to return a reference...

MyndFyre

Quote from: Yoni on July 12, 2004, 04:58 PM
Surely you can see the statement being valid. Just overload operator+ to return a reference...

First, you can't overload operators like that in C#....

Second, Eibro was correct in saying that *(Variable + 6) would be correct syntax.  You'd need to put that within an unsafe code block and also compile with the /unsafe switch.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

K

Quote from: Myndfyre on July 12, 2004, 06:00 PM
Quote from: Yoni on July 12, 2004, 04:58 PM
Surely you can see the statement being valid. Just overload operator+ to return a reference...

First, you can't overload operators like that in C#....

Second, Eibro was correct in saying that *(Variable + 6) would be correct syntax.  You'd need to put that within an unsafe code block and also compile with the /unsafe switch.

Yoni is talking about Eibro's comment that the original code:

(Variable + 6) = Array[5];


could not compile in C++ since (Variable + 6) would not be an L-Value.  He is correct in saying that since we are not given a type for Variable, its possible that the +operator is overloaded and (Variable+6) is returning a reference, and hence a valid L-value.

To convert the code

*(Variable + 6) = Array[5];


to C# probably wouldn't require using unsafe code if we were given more information, such as the type of Variable.  It would simply require changing the pointer arithmatic to an array index.

Eibro

Yes, I thought of that too, but returning a reference from opertor+() doesn't make sense either.
Eibro of Yeti Lovers.