473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3818
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 ::InteropServic es::OutAttribut e] Int32* pn,
[System::Runtime ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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.248.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 ::InteropServic es::OutAttribut e] Int32* pn,
[System::Runtime ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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.248.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 ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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 ::InteropServic es::OutAttribut e] 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
1394
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 that this params are variants. I'm traying to pass "object" variables to the params but the com object return an error or a null object, the piece...
2
15116
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 the outer function, the string.format sets the string-value "System.Object" at the position of {0}. How can i get it work, so that all my values,...
0
1089
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 are called {?PNumber} and {?PName} building a logical AND. They are defined as 'Discrete and Range Values' with the option 'Allow multiple values'...
1
1871
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 Resolution"). -- MJF
3
1646
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 the first index? I have worked around this by getting the MethodInfo via reflection and invoking it there. Is there a simpler way? Thanks, ...
2
1907
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, besides I want use this params in the page, how I can do it to request this params...?? I am using C# like languaje...
6
2561
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 (for example) whose value gets updated via javascript when the user does something, that value is not made available as part of the Request.Params...
8
3153
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, the list/tuple named params will automatically be "expanded" and
3
1869
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
2548
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
7425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7935
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.