jamihuq posted:
Hello,
I would like to convert the following inline function to a macro. Can
someone help?
A retarded six year old, who had three quarters of their brain removed with
a rusty garden sheers, can comprehend that macros just replace text.
What, oh what, is stopping you from typing it out yourself?
Furthermore, why, oh why, would you want to turn an inline function into a
horrible macro?
Do you realise that the C++ code you have presented is absolute dirt? It was
obviously written by a very poor novice. There was no reason to pass the
char pointer by reference. First thing I'll do is make the C++ code a bit
more respectable:
#include <cstring>
#include <cstddef>
#include <cstdlib>
inline char * const fromDESC(const char * const aDesC)
{
using std::size_t;
using std::strlen;
using std::memcpy;
size_t const buf_length = strlen(aDesC) + 1;
char * const res = new char[buf_length];
memcpy( res, aDesC, buf_length );
return res;
}
Now I'll turn that into C:
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
inline char * const fromDESC(const char * const aDesC)
{
size_t const buf_length = strlen(aDesC) + 1;
char * const res = malloc(buf_length);
memcpy( res, aDesC, buf_length );
return res;
}
Now you have a C function which works exactly like the wreckage of a C++
function which you originally presented.
-Tomás