Re: [Dev-C++] Converting macro to inline function.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Matthews <dem...@uw...> - 2003-12-23 15:46:10
|
The only way I can think of is change the original macro call to call the
function instead, ie:
#define CREATE(result,type,number) createf<type>(result,number)
At 07:22 AM 23/12/2003 -0800, David McKen wrote:
>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/
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: IBM Linux Tutorials.
>Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
>Free Linux Tutorials. Learn everything from the bash shell to sys admin.
>Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|