converting inline functions to C functions

J

jamihuq

Hello,
I would like to convert the following inline function to a macro. Can
someone help?

Thx
Jami

inline
char *
fromDESC(const char * &aDesC)
{
char * res;
INT32 ix;
res = PSTRnewL(STRlength(aDesC));
// copy string
for (ix = STRlength(aDesC); ix; ix--, res[ix] = aDesC[ix]);
return(res);
}
 
E

Eric Sosman

jamihuq wrote On 05/16/06 11:35,:
Hello,
I would like to convert the following inline function to a macro. Can
someone help?

Thx
Jami

inline
char *
fromDESC(const char * &aDesC)
{
char * res;
INT32 ix;
res = PSTRnewL(STRlength(aDesC));
// copy string
for (ix = STRlength(aDesC); ix; ix--, res[ix] = aDesC[ix]);
return(res);
}

#define fromDESC(x) -()-

will have the same effect for C, namely, to cause the
compiler to emit a diagnostic.

As an aside, it may interest you to know that there
is a newsgroup called comp.lang.c++ devoted to That
Other Language. Follow-ups set.
 
T

Tomás

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
 
F

Flash Gordon

Tomás wrote:

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:

<snip>

Tomas, you do realise that there is a separate group for C++? It's down
the hall third door on the right called, strangely enough, comp.lang.c++

I realise you were just replying, but you should have taken it to the
correct group rather than posting a long post about C++ in a C group.
 
C

CBFalconer

jamihuq said:
Man, that was uber harsh.

Totally meaningless post. In general on usenet you should realize
that readers may very well not have convenient access to previous
articles in a thread. That means that your reply articles should
include adequate context, so that they stand by themselves. Google
is NOT usenet, it is only a very poor interface to the real usenet
system. To include proper context when using google, see my sig.
below. Please be sure to read the referenced URLs.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
P

pemo

Tomás said:
jamihuq posted:

Furthermore, why, oh why, would you want to turn an inline function
into a horrible macro?

<snip>

Perhaps to guarantee that it *is* 'inlined' - after all, as long as the
compiler recognises the keyword, it's free to ignore it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top