Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   converting inline functions to C functions (http://www.velocityreviews.com/forums/t442790-converting-inline-functions-to-c-functions.html)

jamihuq 05-16-2006 03:35 PM

converting inline functions to C functions
 
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);
}


Eric Sosman 05-16-2006 03:51 PM

Re: converting inline functions to C functions
 


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.

--
Eric.Sosman@sun.com


Tomás 05-16-2006 06:46 PM

Re: converting inline functions to C functions
 
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

Flash Gordon 05-16-2006 07:18 PM

Re: converting inline functions to C functions
 
Tomás wrote:

<snip>

> 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.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

jamihuq 05-16-2006 09:27 PM

Re: converting inline functions to C functions
 
Man, that was uber harsh.


pete 05-16-2006 10:07 PM

Re: converting inline functions to C functions
 
Tomás wrote:

> #include <string.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);
>


if (res != NULL) {

> memcpy( res, aDesC, buf_length );


}

>
> return res;
> }


--
pete

CBFalconer 05-16-2006 11:10 PM

Re: converting inline functions to C functions
 
jamihuq wrote:
>
> 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/>


pemo 05-17-2006 08:46 AM

Re: converting inline functions to C functions
 
Tomás wrote:
> jamihuq posted:
>
>> Hello,
>> I would like to convert the following inline function to a macro. Can
>> someone help?

>
>


<snip>

> 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.

--
==============
Not a pedant
==============




All times are GMT. The time now is 05:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.