Re: Problem with event declaration - possible VS.NET bug?

From: Wild Wind (nobody_at_blackhole.com)
Date: 09/06/04


Date: Mon, 6 Sep 2004 10:13:51 +0100


"Brandon Bray [MSFT]" <branbray@online.microsoft.com> wrote in message
news:O3HE2#7kEHA.1712@TK2MSFTNGP09.phx.gbl...
> Wild Wind wrote:
> > The problem is that with this event declaration, when
> > I compile the code, I get the following errors:
> >
> > error C2059: syntax error : ')'
> > error C2143: syntax error : missing ')' before ';'
> > error C2629: unexpected 'unsigned char ('
> >
> > Each error is shown thrice.
>
> I was able to reproduce this. With the VC2005 40901 compiler, a different
> error message is shown:
>
> t.cpp(6) : error C2697: 'i1' : must explicitly specify __gc or __nogc for
an
> array declared in a managed type
> t.cpp(6) : error C2664: 'C::__Delegate_MyEvent::Invoke' : cannot convert
> parameter 1 from 'unsigned char (*)[1]' to 'unsigned char (*) __gc[]'
> Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-style cast or function-style cast
>
> Both the VC2003 and VC2005 messages are wrong. There's nothing wrong with
> this code. I rewrote it without the typedef as follows:
>
> __event void MyEvent( System::Byte (__nogc*ba)__gc[]);
>
> > Also, when I modified the event declaration to
> >
> > __event void MyEvent(ByteArray ba);
> >
> > the errors went away.
>
> That is correct. The difference is the code without errors is only passing
a
> pointer to an array, whereas the code with errors is passing a __nogc
> pointer to a __gc pointer to an array. I'm guessing that two levels of
> indirection are probably not necessary, so the code without errors is
likely
> something you can use.
>
> > Is this an MS bug? Can anyone reproduce this?
> > If it is a problem, is there anyway I can still
> > declare the event I want to?
>
> I do believe this is a bug. You can file this at the link below, but it's
> not likely to be fixed. In the new syntax, you need to write the delegate
> declaration separately from the event. For example:
>
> delegate void MyDel(array<System::Byte>^* ba);
> event MyDel^ MyEvent;
>
> I don't see anyway to workaround the errors above if you really need to
pass
> a pointer to a pointer to the array. I think the best way is to consider a
> different approach.
>
> Sorry for the inconvenience.

Hello Brandon,

Thanks for your reply. I will file the bug at the link
you mention below. You are probably right about there
not being a need to have the event delegate taking as
an argument a pointer to an array of System::Byte -
I did that because in the documentation, it speaks of
arrays being objects that must be referenced (presumably
using a pointer).

Interestingly enough, you say

    "The difference is the code without errors is only
    passing a pointer to an array"

Is that right? When I declare a managed array of an object,
does this mean that in passing the array, I am implicitly
passing a pointer to the array? And does this also apply
for other managed types, like System::String?

One other question - I take it that the syntax changes
you mention are planned for Whidbey, and the caret (hat)
signifies a managed pointer to an object? What is the
significance the asterisk after the caret you have in

    delegate void MyDel(array<System::Byte>^* ba);

TIA for any answers.

--
Akin
aknak at aksoto dot idps dot co dot uk


Relevant Pages

  • Re: why cannot assign to function call
    ... array to a reference to that array and passing ... the reference by value, and passing the array by reference? ... No, I'm saying that because the parameter has pointer type, not array ...
    (comp.lang.python)
  • Re: getopt in linux
    ... > pointer to an array of pointers to char, ... The second parameter is declared as an array of pointer to ... char, but is immediately converted to a pointer to pointer to char. ... The declaration of the parameter is converted from "array of pointer to ...
    (comp.unix.programmer)
  • Re: getopt in linux
    ... If you mean the parameter list of the declaration, ... pointer to an array of pointers to char, ... And regardless of that conversion, ...
    (comp.unix.programmer)
  • Re: weird code.
    ... never seen this kind of declaration ever. ... The variable data is a float pointer? ... array of 16384 float objects. ...
    (comp.lang.c)
  • Re: Banks and economy
    ... pointer type - which I think is correct for "arrays", and the cptr pointer ... pointer to the 'completing' declaration, ... But no, the standard allows generating a array of 1 member of char, ...
    (alt.lang.asm)