
Signature
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
They don't enforce C#'s out/ref semantics. For example, the following MC++
code compiles fine:
void F1([System::Runtime::InteropServices::OutAttribute] Int32* pi) {}
void F2(Int32* pi) {}
int main()
{
Int32 i, j;
F1(&i);
F2(&j);
}
But the equivalent C# code would fail compilation because:
- F1() doesn't write to *pi before returning.
- j is not written before passed to F2().
Simon
> > Does MC++ support out/ref param semantics (as C# does)? The MC++ spec
> > doesn't mention about this, so supposedly they are not supported?
[quoted text clipped - 14 lines]
>
> C#: void DoSth(out Int32 pn, out System.String ps);
Jochen Kalmbach - 01 May 2004 09:09 GMT
> They don't enforce C#'s out/ref semantics. For example, the following
> MC++ code compiles fine:
>
> void F1([System::Runtime::InteropServices::OutAttribute] Int32*
> pi) {}
H? !?
This is wrong... it will compile but it is wrong..
you have to return an value, for example "*pi = 12"...
> void F2(Int32* pi) {}
This is ok.
> But the equivalent C# code would fail compilation because:
>
> - F1() doesn't write to *pi before returning.
> - j is not written before passed to F2().
H? !?
Please provide a full example...

Signature
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Simon Cheng - 04 May 2004 08:40 GMT
My original question was if MC++ supports C#'s out/ref semantics, which I
also meant if MC++ compiler _enforces_ the restrictions to out/ref as C#
compiler does -- that part I think I was not clear enough up-front. For
example, the following C# code gives compilation errors, which is as
expected:
class MyApp
{
static void F1(out int i) {} // Error CS0177
static void F2(ref int i) {}
public static void Main()
{
int i, j;
F1(out i);
F2(ref j); // Error CS0165
}
}
Error CS0177: The out parameter 'i' must be assigned to before control
leaves the current method
Error CS0165: Use of unassigned local variable 'j'
But the following MC++ code compiles without any error:
#using <mscorlib.dll>
void F1([System::Runtime::InteropServices::OutAttribute] int* pi) {}
void F2(int* pi) {}
int main()
{
int i, j;
F1(&i);
F2(&j);
}
So, supposedly MC++ has no facility that is semantically equivelant to C#'s
out/ref?
Simon
> > They don't enforce C#'s out/ref semantics. For example, the following
> > MC++ code compiles fine:
[quoted text clipped - 17 lines]
> H? !?
> Please provide a full example...
Jochen Kalmbach - 04 May 2004 08:53 GMT
> But the following MC++ code compiles without any error:
>
[quoted text clipped - 12 lines]
> So, supposedly MC++ has no facility that is semantically equivelant to
> C#'s out/ref?
Only the compiler does not ENFORCE this. But this is common to all C++
compilers that you can do more or less if you want...
C++ also does not restrict casting... or use of void-pointers...
If you want a type-safe and "language-safe" language you must use C# (or
any other langugate that supports what you want...)
Recapitulating we can say: C++ needs a higher learning curve that C#, and
you can do musch more "bad things" than with C#.

Signature
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
Simon Cheng - 04 May 2004 18:09 GMT
That's the reason I am wondering if MC++ (as opposed to C++) can enforce
C#'s out/ref semantic, as MC++ has already provided some other C# facilities
via additional keywords. I am working on some code that needs to be done in
MC++, and equivalent facility to enforce out/ref would be nice.
Simon
> > But the following MC++ code compiles without any error:
> >
[quoted text clipped - 23 lines]
> Recapitulating we can say: C++ needs a higher learning curve that C#, and
> you can do musch more "bad things" than with C#.
Doug Harrison [MVP] - 04 May 2004 18:28 GMT
>They don't enforce C#'s out/ref semantics. For example, the following MC++
>code compiles fine:
[quoted text clipped - 13 lines]
> - F1() doesn't write to *pi before returning.
> - j is not written before passed to F2().
Compilers are free to ignore the OutAttribute. The C# language respects the
attribute, and C# disallows the F2 call because of its "definite assignment"
requirement. C++ supports neither feature.

Signature
Doug Harrison
Microsoft MVP - Visual C++