Question about a variable argument list in managed c++ 
Author Message
 Question about a variable argument list in managed c++

I am trying to get a function to have a variable length
argument list. I used the standard '...' parameter, but it
fails miserably with the following error:

c:\code\varargtest\varargtest.cpp(16): error
C3269: 'vatest::add' : a member-function of a managed type
cannot be declared with '...'

And the funniest part is the resolution provided by
Microsoft:
// C3269, remove ', ...' to resolve

I cannot use the 'params' attribute because that is C#
specific. I cannot use va_list because '...' is not
supported. Does anybody know a way to accept a variable
length argument list?

Also, in addition to that, can you tell me how to identify
the type of each object at runtime?

Thanks,
MT



Mon, 21 Feb 2005 23:52:23 GMT  
 Question about a variable argument list in managed c++
Use the [ParamArray] attribute with an argument array. You can interact with
the argument as you would any other array, including iterating over it and
calling GetType to obtain the runtime type. For example:

#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;

ArrayList* GetArrayList([ParamArray] Object* strs[]) {
 ArrayList *pal = new ArrayList();
 ICollection *pcol = dynamic_cast<ICollection*>(strs);
 pal->AddRange(pcol);
 return pal;

Quote:
}

main() {
 Object *pobjs[] = { S"Hello", S"World", __box(42) };
 ArrayList *pal = GetArrayList(pobjs);
 IEnumerable *pie = dynamic_cast<IEnumerable*>(pal);
 IEnumerator *penum = pie->GetEnumerator();
 while (penum->MoveNext()) {
  Object *pcur = penum->get_Current();
  Type *pt = pcur->GetType();
  Console::WriteLine(pt);
 }

Quote:
}

--Peter
http://www.razorsoft.net/weblog
http://staff.develop.com/peterd


Quote:
> I am trying to get a function to have a variable length
> argument list. I used the standard '...' parameter, but it
> fails miserably with the following error:

> c:\code\varargtest\varargtest.cpp(16): error
> C3269: 'vatest::add' : a member-function of a managed type
> cannot be declared with '...'

> And the funniest part is the resolution provided by
> Microsoft:
> // C3269, remove ', ...' to resolve

> I cannot use the 'params' attribute because that is c#
> specific. I cannot use va_list because '...' is not
> supported. Does anybody know a way to accept a variable
> length argument list?

> Also, in addition to that, can you tell me how to identify
> the type of each object at runtime?

> Thanks,
> MT



Tue, 22 Feb 2005 00:40:11 GMT  
 Question about a variable argument list in managed c++
But that does not look like a truly variable argument list
accepting function:

I have to create an array of Object * and then pass it to
the function, that seems counter intuitive to the user who
just expects to put in a variable argument list....

I don't understand why you cannot do something like the
following piece of code in c#:

  public static void argit0( __arglist )
     {
     ArgIterator args = new ArgIterator( __arglist );
     TypedReference trTypRef = args.GetNextArg();
     }

I was really e{*filter*}d when I heard that variable argument
list was built into the system code. But it seems that I
cannot use it in the same way I intended to use it :(

That was an interesting piece of code though....

MT

Quote:
>-----Original Message-----
>Use the [ParamArray] attribute with an argument array. You
can interact with
>the argument as you would any other array, including

iterating over it and
Quote:
>calling GetType to obtain the runtime type. For example:

>#using <mscorlib.dll>
>using namespace System;
>using namespace System::Collections;

>ArrayList* GetArrayList([ParamArray] Object* strs[]) {
> ArrayList *pal = new ArrayList();
> ICollection *pcol = dynamic_cast<ICollection*>(strs);
> pal->AddRange(pcol);
> return pal;
>}

>main() {
> Object *pobjs[] = { S"Hello", S"World", __box(42) };
> ArrayList *pal = GetArrayList(pobjs);
> IEnumerable *pie = dynamic_cast<IEnumerable*>(pal);
> IEnumerator *penum = pie->GetEnumerator();
> while (penum->MoveNext()) {
>  Object *pcur = penum->get_Current();
>  Type *pt = pcur->GetType();
>  Console::WriteLine(pt);
> }
>}

>--Peter
> http://www.*-*-*.com/
> http://www.*-*-*.com/




>> I am trying to get a function to have a variable length
>> argument list. I used the standard '...' parameter, but it
>> fails miserably with the following error:

>> c:\code\varargtest\varargtest.cpp(16): error
>> C3269: 'vatest::add' : a member-function of a managed type
>> cannot be declared with '...'

>> And the funniest part is the resolution provided by
>> Microsoft:
>> // C3269, remove ', ...' to resolve

>> I cannot use the 'params' attribute because that is c#
>> specific. I cannot use va_list because '...' is not
>> supported. Does anybody know a way to accept a variable
>> length argument list?

>> Also, in addition to that, can you tell me how to identify
>> the type of each object at runtime?

>> Thanks,
>> MT

>.



Tue, 22 Feb 2005 03:00:49 GMT  
 Question about a variable argument list in managed c++
The extra step in passing this kind of arguments is only in MC++
(currently),
C#/VB.NET will understand it just fine:

http://www.*-*-*.com/
be4cedf9c5d9c17&seekm=uZlhAICACHA.1836%40tkmsftngp05#link1


Quote:
> But that does not look like a truly variable argument list
> accepting function:

> I have to create an array of Object * and then pass it to
> the function, that seems counter intuitive to the user who
> just expects to put in a variable argument list....

> I don't understand why you cannot do something like the
> following piece of code in c#:

>   public static void argit0( __arglist )
>      {
>      ArgIterator args = new ArgIterator( __arglist );
>      TypedReference trTypRef = args.GetNextArg();
>      }

> I was really e{*filter*}d when I heard that variable argument
> list was built into the system code. But it seems that I
> cannot use it in the same way I intended to use it :(

> That was an interesting piece of code though....

> MT

> >-----Original Message-----
> >Use the [ParamArray] attribute with an argument array. You
> can interact with
> >the argument as you would any other array, including
> iterating over it and
> >calling GetType to obtain the runtime type. For example:

> >#using <mscorlib.dll>
> >using namespace System;
> >using namespace System::Collections;

> >ArrayList* GetArrayList([ParamArray] Object* strs[]) {
> > ArrayList *pal = new ArrayList();
> > ICollection *pcol = dynamic_cast<ICollection*>(strs);
> > pal->AddRange(pcol);
> > return pal;
> >}

> >main() {
> > Object *pobjs[] = { S"Hello", S"World", __box(42) };
> > ArrayList *pal = GetArrayList(pobjs);
> > IEnumerable *pie = dynamic_cast<IEnumerable*>(pal);
> > IEnumerator *penum = pie->GetEnumerator();
> > while (penum->MoveNext()) {
> >  Object *pcur = penum->get_Current();
> >  Type *pt = pcur->GetType();
> >  Console::WriteLine(pt);
> > }
> >}

> >--Peter
> > http://www.*-*-*.com/
> > http://www.*-*-*.com/




> >> I am trying to get a function to have a variable length
> >> argument list. I used the standard '...' parameter, but it
> >> fails miserably with the following error:

> >> c:\code\varargtest\varargtest.cpp(16): error
> >> C3269: 'vatest::add' : a member-function of a managed type
> >> cannot be declared with '...'

> >> And the funniest part is the resolution provided by
> >> Microsoft:
> >> // C3269, remove ', ...' to resolve

> >> I cannot use the 'params' attribute because that is c#
> >> specific. I cannot use va_list because '...' is not
> >> supported. Does anybody know a way to accept a variable
> >> length argument list?

> >> Also, in addition to that, can you tell me how to identify
> >> the type of each object at runtime?

> >> Thanks,
> >> MT

> >.



Tue, 22 Feb 2005 04:08:52 GMT  
 Question about a variable argument list in managed c++
Argiterators (including the C# syntax you mention) aren't a supported
feature in any MS .Net language right now and aren't use in any of the base
class libraries or frameworks. In addition the implementation is currently
very slow. Instead those places use the ParamArray pattern (for which there
is no direct C++ support in 7.x).

For C++ we are looking at supporting both ParamArrays in a C# similar way
and argiterators in the release beyond 7.1.

Ronald Laeremans
Visual C++ compiler team


Quote:
> But that does not look like a truly variable argument list
> accepting function:

> I have to create an array of Object * and then pass it to
> the function, that seems counter intuitive to the user who
> just expects to put in a variable argument list....

> I don't understand why you cannot do something like the
> following piece of code in c#:

>   public static void argit0( __arglist )
>      {
>      ArgIterator args = new ArgIterator( __arglist );
>      TypedReference trTypRef = args.GetNextArg();
>      }

> I was really e{*filter*}d when I heard that variable argument
> list was built into the system code. But it seems that I
> cannot use it in the same way I intended to use it :(

> That was an interesting piece of code though....

> MT

> >-----Original Message-----
> >Use the [ParamArray] attribute with an argument array. You
> can interact with
> >the argument as you would any other array, including
> iterating over it and
> >calling GetType to obtain the runtime type. For example:

> >#using <mscorlib.dll>
> >using namespace System;
> >using namespace System::Collections;

> >ArrayList* GetArrayList([ParamArray] Object* strs[]) {
> > ArrayList *pal = new ArrayList();
> > ICollection *pcol = dynamic_cast<ICollection*>(strs);
> > pal->AddRange(pcol);
> > return pal;
> >}

> >main() {
> > Object *pobjs[] = { S"Hello", S"World", __box(42) };
> > ArrayList *pal = GetArrayList(pobjs);
> > IEnumerable *pie = dynamic_cast<IEnumerable*>(pal);
> > IEnumerator *penum = pie->GetEnumerator();
> > while (penum->MoveNext()) {
> >  Object *pcur = penum->get_Current();
> >  Type *pt = pcur->GetType();
> >  Console::WriteLine(pt);
> > }
> >}

> >--Peter
> > http://www.*-*-*.com/
> > http://www.*-*-*.com/




> >> I am trying to get a function to have a variable length
> >> argument list. I used the standard '...' parameter, but it
> >> fails miserably with the following error:

> >> c:\code\varargtest\varargtest.cpp(16): error
> >> C3269: 'vatest::add' : a member-function of a managed type
> >> cannot be declared with '...'

> >> And the funniest part is the resolution provided by
> >> Microsoft:
> >> // C3269, remove ', ...' to resolve

> >> I cannot use the 'params' attribute because that is c#
> >> specific. I cannot use va_list because '...' is not
> >> supported. Does anybody know a way to accept a variable
> >> length argument list?

> >> Also, in addition to that, can you tell me how to identify
> >> the type of each object at runtime?

> >> Thanks,
> >> MT

> >.



Tue, 22 Feb 2005 07:45:57 GMT  
 Question about a variable argument list in managed c++

Quote:
> For C++ we are looking at supporting both ParamArrays in a C# similar way
> and argiterators in the release beyond 7.1.

Is there a list of all the .NET 'features' that exist, but are not supported
in any MS language?

-Sean



Tue, 22 Feb 2005 22:44:00 GMT  
 Question about a variable argument list in managed c++
No, you can look in the ECMA specs and figure it out, but I don't know of
any list. I also don't quite understand what the usefulness would be. We
have designed the CLR to be very flexible and support all kinds of
languages, so the fact that no Microsoft languages uses a certain feature
doesn't exactly mean much. E.g. Microsoft doesn't sell any functional
programming languages so any features in the CLR to support this class of
languages won't be used by any Microsoft language. A simple example of that
is tail calls.

Ronald


Quote:
> > For C++ we are looking at supporting both ParamArrays in a C# similar
way
> > and argiterators in the release beyond 7.1.

> Is there a list of all the .NET 'features' that exist, but are not
supported
> in any MS language?

> -Sean



Wed, 23 Feb 2005 01:50:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. variable argument lists (va_arg)--determining number of arguments

2. Variable Argument List Question

3. Variable argument list question

4. questions on variable argument lists

5. variable parameter argument in managed class

6. Checking for NULL arguments in Managed C++

7. Preprocessor Variable argument lists

8. calling unmanaged function with variable list of arguments (ellipses) failed

9. variable argument lists

10. Passing variable lenght argument list

11. Passing variable argument list

12. Call interpreted variable argument list

 

 
Powered by phpBB® Forum Software