[Dev-C++] Converting macro to inline function.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-12-23 15:22:29
|
I am cleaing up some code and came across the following macro:
#define CREATE(result, type, number) \
do \
{ \
if (!((result) = (type *) calloc ((number), sizeof(type)))) \
{ \
perror("malloc failure"); \
fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__, __LINE__ );
\
abort(); \
} \
} while(0)
I want to convert to a function (most likely inline, its small
enough) the problme I am having is with the second parameter, it is a
data type!
So far the following seems like it would work:
template<class type>
inline void CREATE(result, number)
{
if (!((result) = (type *) calloc ((number), sizeof(type))))
{
perror("malloc failure");
fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__, __LINE__ );
abort();
}
}
The problem is this macro is quite heavily used. Changing the
function to the following would require me to change the "macro call"
to the following function call:
CREATE<int>(pToSomewhere, 500); //To create 500 ints.
Is there around this or will I also have to change all the function
calls?
Thanks in Advance.
David McKen
P.S. I am lazy, I admit it. I don't want to change all those lines of
code, if I have to so be it. I am changing this macro to a function.
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
|