错误 - 声明但未定义:静态和静态内联函数

时间:2021-05-19 14:22:11

标签: c static inline

我正在使用 vc++/Microsoft Visual Studio 编辑器编写一个静态内联函数。我的代码是这样写的

文件 main.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "foo.h"

void main()
{       
    int32_t a = { 0 }, b = 3, c = 4, d = {0};

    foo(b, c, &d);
    a = a + d;
    printf("a = %10d\n", a);

}

文件 foo.c

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include "foo.h"

static inline int32_t foo(int32_t b, int32_t c, int32_t* d)
{
    return(*d = (b + c) >> 1);
}

文件 foo.h

#include <stdio.h>
#include <stdint.h>

static inline int32_t foo(int32_t b, int32_t c, int32_t* d);

当我构建代码时,我收到一个错误

error C2129: static function 'int32_t foo(int32_t,int32_t,int32_t *)' declared but not defined.

如果函数在同一个文件中使用,它们将是内联的,但是如果所有内联函数都移动到头文件中会发生什么。如何使函数 foo() 成为静态内联函数?

我不明白问题出在哪里/跨文件的静态内联函数背后的概念是什么。

0 个答案:

没有答案
相关问题