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