Quick Q: Calling C++ Application Code from C library?

Quick A: You need to create a stub.

Recently on SO:

Calling C++ Application Code from C library?

Folks, Assuming I have a c++ application / library running which implements say

/* Alloc API */
void* my_alloc(int size) {
    return malloc(sizeof(size));
}

This is not under "extern c".

I have a C dynamic library from which I need to call my_alloc, can I directly call that API?

Like,

int test_my_alloc (int size) {
    int *x;

    x = (int*)my_alloc(size);
    if (x == NULL) {
        return 0;
    } else {
        return 1;
    }
}

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.