Gustavo Salomão
Gustavo Salomão

Reputation: 93

Call function in a static library without implementation

I'd like to know if it's possible, within a static library, call a function that the implementation is in my application instead of in the library.

Like this:

Static Library

foo.h

void foo_func();

foo.c

#include "foo.h"

void foo_func()
{
    app_func();
}

Application

main.c

#include <foo.h>

uint8_t flag = FALSE;

uint8 main()
{
    foo_func();

    while(!flag);

    return 0;
}

void app_func()
{
     flag = TRUE;
}

Upvotes: 3

Views: 377

Answers (1)

ouah
ouah

Reputation: 145899

A static library created with ar is just an archive of .o object files. You can call any external functions in static library created with ar, present or not, like with any .o file. While it is possible, calling back the application is may be not the best design choice.

Upvotes: 1

Related Questions