473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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?
Nov 17 '05 #1
1 1106
mccoyn <an*******@discussions.microsoft.com> wrote:
[...]
#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...1.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.

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Ellis | last post by:
Hi, I'm trying to write a macro that will generate managed c++ wrappers of map. I want a managed iterator and a managed map. I successfully built a pair of classes (iterator and map) that work...
2
by: Gustavo L. Fabro | last post by:
Greetings. Is there a way to run the preprocessor twice? Rephrasing that, is there a way to: #define SOMETHING #pragma OTHERTHING and have the preprocessor in somecode.cpp evaluate: ...
2
by: Chris Dunaway | last post by:
I am using the following code in a macro to attach to a process: Dim sFilename As String = "progname.exe" Dim proc As EnvDTE.Process For Each proc In DTE.Debugger.LocalProcesses If...
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
6
by: thomas.luce | last post by:
Okay, I have been programming for a long time, and am getting back into C after about a 4 year break from it. Below is some code that won't compile for the life of me, and it is driving me crazy!...
5
by: keri | last post by:
Hi, I am struggling to learn access and VBA whilst creating a db, progress is slow! So far I have managed to run cascading combo boxes on a form by using a sub in the after update procedure of...
20
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known C compilers? gcc compiler supports typeof()...
2
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report...
7
by: nsharish20 | last post by:
Hi, I am a beginner with Access but I have managed to play around with VB and macros. I have a query called "qryClosure". In this database, I have fields like Report #, Customer #, CA Resp,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.