Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Forward declarations and #pragma managed/unmanaged

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gustavo L. Fabro - 29 Jun 2005 19:13 GMT
Greetings!

Going directly to the point:

myclass.h:
//--------------------------------------

#pragma managed

//Forward declaration
class AnotherClass;

#pragma unmanaged

class MyClass
{
   public:
       void func1(AnotherClass* ptr);
}

Will this '#pragma managed' before 'class AnotherClass' have any effect at
all on my native class? I know the forwad declaration only puts the symbol's
name under the symbols table, but I was wondering if, being defined under
'managed' setting, this symbol would have any thunking layers or anything
like that that would make it's access slower.

Thanks,

Fabro
Carl Daniel [VC++ MVP] - 29 Jun 2005 21:02 GMT
> Greetings!
>
[quoted text clipped - 22 lines]
> thunking layers or anything like that that would make it's access
> slower.

Based on a very simply experiment, it doesn't appear to make any difference.
What matters is whether #pragma managed is in effect where the class
definition appears.

<code>
#pragma managed

//Forward declaration
class AnotherClass;

#pragma unmanaged

class MyClass
{
   public:
       void func1(AnotherClass* ptr) {}
};

#pragma unmanaged    // 1

class AnotherClass
{
   public:
void f() {}
};
</code>

If the line at //1 is #pragma unmanaged, the resulting .obj looks identical
to that produced if // 1 is deleted.  It // 1 is #pragma managed,
AnotherClass::f() is emitted as managed code.

-cd
Gustavo L. Fabro - 01 Jul 2005 14:42 GMT
Hmmm

I took your idea and compiled these files

#1

#pragma managed
class AnotherClass;
#pragma unmanaged

class MyClass
{
   public:
       void func1(AnotherClass* ptr);
}

#2

#pragma unmanaged
class AnotherClass;
#pragma unmanaged

class MyClass
{
   public:
       void func1(AnotherClass* ptr);
}

The obj files have the same size but are different. But that doesn't tell
*me* much, because If I compile the same file twice, different (binary
speaking) obj files will be created too.

Fabro
Carl Daniel [VC++ MVP] - 01 Jul 2005 15:08 GMT
> Hmmm
>
[quoted text clipped - 28 lines]
> (binary
> speaking) obj files will be created too.

Use dumpbin /all on the .OBJ files to see the internals.  I didn't do a very
thorough examination, but at the level I did look, it appeared that no
significant changes to the file were made.  In your example, there's no code
being generated at all, so I think you need to embelish the test case just a
bit to make it meaningful.

-cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.