473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

out/ref params

Hi,

Does MC++ support out/ref param semantics (as C# does)? The MC++ spec
doesn't mention about this, so supposedly they are not supported?

Thanks,
Simon
Nov 17 '05 #1
7 3813
Simon Cheng wrote:
Does MC++ support out/ref param semantics (as C# does)? The MC++ spec
doesn't mention about this, so supposedly they are not supported?


Yes.

For ref:
MC++: void DoSth(
Int32* pn,
System::String** ps);

C#: void DoSth(ref Int32 pn, ref System.String ps);
For out:
MC++: void DoSth(
[System::Runtime::InteropServices::OutAttribute] Int32* pn,
[System::Runtime::InteropServices::OutAttribute] System::String** ps);

C#: void DoSth(out Int32 pn, out System.String ps);
--
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/
Nov 17 '05 #2
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

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn**********************************@207.46.2 48.16...
Simon Cheng wrote:
Does MC++ support out/ref param semantics (as C# does)? The MC++ spec
doesn't mention about this, so supposedly they are not supported?


Yes.

For ref:
MC++: void DoSth(
Int32* pn,
System::String** ps);

C#: void DoSth(ref Int32 pn, ref System.String ps);
For out:
MC++: void DoSth(
[System::Runtime::InteropServices::OutAttribute] Int32* pn,
[System::Runtime::InteropServices::OutAttribute] System::String** ps);

C#: void DoSth(out Int32 pn, out System.String ps);
--
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/

Nov 17 '05 #3
Simon Cheng wrote:
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...

--
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/
Nov 17 '05 #4
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

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn**********************************@207.46.2 48.16...
Simon Cheng wrote:
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...

--
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/

Nov 17 '05 #5
Simon Cheng wrote:
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?


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#.

--
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/
Nov 17 '05 #6
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

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
Simon Cheng wrote:
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?


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#.

--
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/

Nov 17 '05 #7
Simon Cheng wrote:
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().


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.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mihaly | last post by:
Hello, i'm using a VC++ com+ object, it's reference in vs .net, this com object have a function that have to params, the interop com object recive Object Params and the original com object say...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
0
by: Dominik Tropper | last post by:
Dear all I have created a c# web project in VS.NET 2003 that contains a crystal report with two params. No problems until here, but executing the report selects the wrong records. My params...
1
by: M Jared Finder | last post by:
What are the rules for method overload resolution when there are functions with a params argument? No mention of params is made in section 7.4.2 of the C# specification on MSDN (titled "Overload...
3
by: Stan Huff | last post by:
Is there any way to disable the "params" on a particular invocation so that one can pass an array containing the arguments and not have receiver get an array having you argument array stuffed into...
2
by: Coneection OLAP | last post by:
Hi: Me question is the next: I would like know how, I can do it to pass params, from a control of a page ASPX to other page ASPX, but I don't want that this params can see in the URL, ...
6
by: Praveen | last post by:
As you all know the value of input, checkbox and other "user editable" elements can be retrieved on postback via Request.Params list, if you know their ID. However, if there is a span element...
8
by: David Duerrenmatt | last post by:
Hi there For some reasons, I've to use Python 1.5.2 and am looking for a workaround: In newer Python versions, I can call a function this way: func = some_function func(*params) Then,...
3
by: rushik | last post by:
Hello, In our code i've seen somewhere fun1()->fun2(params), i m not able to understand what it means? our code is completely written in C++. Thanks Ru.
2
by: FFMG | last post by:
Hi, I was looking at http://www.php.net/manual/en/function.call-user-func-array.php and I was wondering... Given, // -- function foo( &$params) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.