c/c++中的__attribute__((weak))使用


main.cpp

#include <stdio.h>
#include "g_test.h"

extern bool testFunc();

bool  __attribute__((weak))testFunc()
{
    warnf("this is weak api\n");
    return false;
}

int main()
{
    testFunc();
    return 0;
}

 g_test.h

#ifndef  __G_TEST_H_
#define __G_TEST_H_


bool testFunc();

#endif

 g_test.cpp

#include "g_test.h"
#include <stdio.h>

bool testFunc()
{
    printf("this  is strong api\n");
    return false;
}

輸出結果是調用到g_test.cpp中的testFunc函數中

如果g_test.cpp中沒有實現,則調用的__attribute__((weak))的函數

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM