本文介绍: 使用示例将 函数标记为已弃用,并建议使用 函数代替。

标记函数为已弃用宏:WHISPER_DEPRECATED

  • 对于 GNU 编译器(__GNUC__),使用 __attribute__((deprecated(hint))) 属性将函数标记为已弃用,并附带指定的提示信息。
  • 对于微软 Visual C++ 编译器(_MSC_VER),使用 __declspec(deprecated(hint)) 属性实现相同的目的。
  • 对于其他编译器,函数不会被标记为已弃用。
// 检查是否为 GNU 编译器
#ifdef __GNUC__
    // 对于 GNU 编译器,使用 __attribute__((deprecated(hint))) 将函数标记为已弃用
    // hint 参数用于提供关于已弃用的提示信息
    #define WHISPER_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
// 检查是否为 Microsoft Visual C++ 编译器
#elif defined(_MSC_VER)
    // 对于 Microsoft Visual C++ 编译器,使用 __declspec(deprecated(hint)) 将函数标记为已弃用
    // hint 参数用于提供关于已弃用的提示信息
    #define WHISPER_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
// 其他编译器
#else
    // 对于其他编译器,不进行已弃用标记
    #define WHISPER_DEPRECATED(func, hint) func
#endif

使用示例

  • whisper_init_from_file_no_state 函数标记为已弃用,并建议使用 whisper_init_from_file_with_params_no_state 函数代替。
    WHISPER_DEPRECATED(
        WHISPER_API struct whisper_context * whisper_init_from_file_no_state(const char * path_model),
        "use whisper_init_from_file_with_params_no_state instead"
    );

WHISPER_API

// 如果定义了 WHISPER_SHARED
#ifdef WHISPER_SHARED
    // 如果目标平台为 Windows(_WIN32)
    #ifdef _WIN32
        // 如果是构建共享库(WHISPER_BUILD 已定义)
        #ifdef WHISPER_BUILD
            // 定义 WHISPER_API 为 __declspec(dllexport)(导出符号)
            #define WHISPER_API __declspec(dllexport)
        // 如果是使用共享库(WHISPER_BUILD 未定义)
        #else
            // 定义 WHISPER_API 为 __declspec(dllimport)(导入符号)
            #define WHISPER_API __declspec(dllimport)
        #endif
    // 如果目标平台不是 Windows
    #else
        // 定义 WHISPER_API 为 __attribute__ ((visibility ("default")))(设置可见性为默认)
        #define WHISPER_API __attribute__ ((visibility ("default")))
    #endif
// 如果未定义 WHISPER_SHARED
#else
    // 定义 WHISPER_API 为空
    #define WHISPER_API
#endif

  • 注:宏定义使用 #define 关键字,定义 WHISPER_API 为空时(#define WHISPER_API),由于编译器在预处理阶段会将这些宏的出现替换为相应的代码或值。定义为空即什么也不做。

__declspec(dllimport) 和 __declspec(dllexport)

__declspec(dllimport)

  1. 作用

    • 用于标记在外部 DLL 中定义的函数或变量,表示这些函数或变量将在运行时从 DLL 中导入到当前模块(通常是可执行文件或其他 DLL)中使用。
  2. 示例

    // 在可执行文件或其他 DLL 中使用的声明
    __declspec(dllimport) void myFunction();
    __declspec(dllimport) int myVariable;
    

__declspec(dllexport)

  1. 作用

    • 用于标记在当前模块中定义的函数或变量,表示这些函数或变量将在运行时导出到 DLL 中,以便其他模块可以使用。
  2. 示例

    // 在 DLL 中定义的导出函数和变量
    __declspec(dllexport) void myFunction() {
        // 函数体
    }
    __declspec(dllexport) int myVariable = 42;
    

使用示例

WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model);

原文地址:https://blog.csdn.net/ResumeProject/article/details/135903259

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_64965.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注