converting inline functions to C functions

Discussion in 'C Programming' started by jamihuq, May 16, 2006.

  1. jamihuq

    jamihuq Guest

    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);
    }
     
    jamihuq, May 16, 2006
    #1
    1. Advertising

  2. jamihuq

    Eric Sosman Guest

    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, May 16, 2006
    #2
    1. Advertising

  3. jamihuq

    Tomás Guest

    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
     
    Tomás, May 16, 2006
    #3
  4. jamihuq

    Flash Gordon Guest

    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
     
    Flash Gordon, May 16, 2006
    #4
  5. jamihuq

    jamihuq Guest

    Man, that was uber harsh.
     
    jamihuq, May 16, 2006
    #5
  6. jamihuq

    pete Guest

    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
     
    pete, May 16, 2006
    #6
  7. jamihuq

    CBFalconer Guest

    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/>
     
    CBFalconer, May 17, 2006
    #7
  8. jamihuq

    pemo Guest

    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
    ==============
     
    pemo, May 17, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhi
    Replies:
    2
    Views:
    757
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    495
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    479
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,993
    Kevin Bracey
    Nov 21, 2003
  5. Rahul
    Replies:
    3
    Views:
    468
    James Kanze
    Feb 28, 2008
Loading...

Share This Page