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++ / May 2004

Tip: Looking for answers? Try searching our database.

Is there a way to tell if a macro paramerter is managed?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mccoyn - 12 May 2004 14:21 GMT
I have a macro that can determine the number of elements in an array type.  It is defined as follows

#define ARRAY_SIZE_NOGC(x) (sizeof(x) / sizeof(x[0])

This works with unmanaged array types, but not with pointers, since the size of a pointer is always the same and not the size of the data it points to.  Obviously this doesn't work with managed types, which are all refered to by pointers.  I could define the macro to handle managed arrays as follows

#define ARRAY_SIZE_GC(x) (x->Length

The problem is these two macros arn't generic.  I would like one macro that would work for both.  Something like the following

#define ARRAY_SIZE(x) ( IS_A_GC_POINTER(x) ? ARRAY_SIZE_GC(x) : ARRAY_SIZE_NOGC(x)

Is there a way to implement the IS_A_GC_POINTER macro above?
Hendrik Schober - 12 May 2004 15:56 GMT
> [...]
> #define ARRAY_SIZE(x) ( IS_A_GC_POINTER(x) ? ARRAY_SIZE_GC(x) : ARRAY_SIZE_NOGC(x) )
>
> Is there a way to implement the IS_A_GC_POINTER macro above?

 I have no idea of MC++, but if you don't need
 this information at compile-time, then maybe
 overloading at run-time would help? Look if
 this
   http://groups.google.com/groups?selm=6ntce1%2445f%241%40nnrp1.dejanews.com
 solution gets you somewhere.

 Schobi

 P.S.: Oh, I'm just thinking that if you use a
       template class, instead of the template
       function, you should get the size at
       compile-time as well. Something like
       this (uncompiled code!)

         template< typename T >
         struct ArraySize;  // undefined

         template< typename T, CCW_CSTD::size_t sz >
         struct ArraySize<T[sz]> {enum {result=sz};}

       might do.

Signature

SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
 Scott Meyers


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.