Thread: How do I wrap this?

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    29

    How do I wrap this?

    I ported the PCRE2 open source library to the mainframe (works like a charm.) Now my task is to provide an API for old style languages that are used in that environment. One thing that I have to do is provide a 8 character max shorthand names to the available API functions. (I know that you are rolling your eyes, but that's the nature of the beast What I do is to wrap the native long name function with a shorthand name function with identical signature.
    For example:
    The original package has
    Code:
    PCRE2_SPTR pcre2_get_mark(pcre2_match_data *match_data);
    I wrap it with:
    Code:
    extern PCRE2_SPTR GETMARK(pcre2_match_data *match_data); 
    .
    .
    PCRE2_SPTR GETMARK(pcre2_match_data *match_data) 
    { 
    return pcre2_get_mark(match_data); 
    }
    So now the old style languages may CALL "GETMARK" ...
    This solution works fine and is the desirable solution. But here is the problem, one of the functions have a signature that I do not understand and certainly do not know how to wrap as described above:
    Code:
    pcre2_general_context *pcre2_general_context_create( 
    void *(*private_malloc)(PCRE2_SIZE, void *), 
    void (*private_free)(void *, void *), void *memory_data);
    Do you have any idea how to do the wrapper:
    Code:
    pcre2_general_context *GENCNTCR( 
    void *(*private_malloc)(PCRE2_SIZE, void *), 
    void (*private_free)(void *, void *), void *memory_data) 
    { 
    return .......; 
    }
    Thank you
    ZA

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    It's just:
    Code:
    return pcre2_general_context_create(private_malloc, private_free, memory_data);
    You need to brush up on function pointers.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    29
    Thank you so much
    I will try that
    And yes, certainly I need to brush up on function pointers

    ZA

    Quote Originally Posted by algorism View Post
    It's just:
    Code:
    return pcre2_general_context_create(private_malloc, private_free, memory_data);
    You need to brush up on function pointers.

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by zatlas1 View Post
    And yes, certainly I need to brush up on function pointers
    Function pointers are a little weird looking. The basic idea is to start with a prototype:
    Code:
    int myfunc (const char *s);
    Then put parentheses around the name and add an asterisk before it:
    Code:
    int (*myfunc) (const char *s);
    That's a function pointer! It's name is myfunc. You can use it like this:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int afunc(const char *s) {
        return (int)strlen(s);
    }
    
    int main() {
        int (*myfunc) (const char *s) = afunc;
        int n = myfunc("hello");
        printf("%d\n", n);
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wrap around in array
    By lamko in forum C Programming
    Replies: 22
    Last Post: 08-17-2011, 12:24 PM
  2. It's a wrap!
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-10-2007, 02:00 PM
  3. Word Wrap
    By Fireblade2006 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2006, 03:09 PM
  4. Word wrap
    By Orrill in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2005, 02:00 PM
  5. Can't wrap my brain around this:
    By swayp in forum C++ Programming
    Replies: 3
    Last Post: 01-29-2005, 02:57 PM

Tags for this Thread