Re: Mixing Mananged and Unmanaged in an Unmanaged class

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Russell Hind (rhind_at_mac.com)
Date: 06/04/04


Date: Fri, 04 Jun 2004 08:21:24 +0100

Yan-Hong Huang[MSFT] wrote:
>
> We decided to make it an error, not a warning. The workaround is to define the function outside the class.
>

So the compiler decides whether the function is managed or unmanaged at
the point it is defined (implemented) not declared?

I have a problem in that if I have #pragma unmanaged before a class (non
gc class), and the class contains a gcroot<T*> as a private memeber,
then I get compiler errors. Inserting a #pragma managed and unmanaged
around the declaration solve this. e.g.

__gc class GCTest_c;

#pragma unmanaged
class Test_c
{
public:
     Test_c(void)
     {
     }

private:
     gcroot<GCTest_c*> m_Test;
};

This doesn't compile, but can be fixed by putting #pragam
managed/unmanged around the m_Test declaration. e.g.

#pragma unmanaged
class Test_c
{
public:
     Test_c(void)
     {
     }

private:
#pragma managed
     gcroot<GCTest_c*> m_Test;
#pragma unmanaged
};

But according to your replies, this shouldn't be done. So is this a bug?

Thanks

Russell



Relevant Pages

  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... than it would be if the declaration created and really ... I understand why the VLA rules are the way they are. ...
    (comp.std.c)
  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... the same way it does for VLAs? ... I write an intra-block declaration and every time I read one I ...
    (comp.std.c)
  • Re: C-AUX / C and binary portability
    ... trigraphs, digraphs, and K&R declarations are, in many C compilers, currently at the level where they will cause compiler warnings. ... which is ambiguous, but in this case, it will just assume that the declaration was intended. ... the reason is that, if one does infact include headers and expand macros here, then the generated code will depend on whatever macros/constants/... ...
    (comp.lang.misc)
  • Re: Question about multiple files
    ... No. extern just means: The actual definition is somewhere else. ... the compiler can differentiate between declaration and definition just ... > declaration it finds and in this way can I write code expecting it to be ... When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... than it would be if the declaration created and really ... If my semantics were in effect, you could trivially transform a "My C" program into an equivalent C99 program by adding a pair of braces to mark the lifetime of every automatic object, and then you could forget about the difference between my semantics and C99. ... The VLA rules make correctness arguments more difficult. ...
    (comp.std.c)