我继续无法在以下(c)代码中找到任何错误。然而,编译器正在向我抛出错误。使用union时.c包含文件中的多个错误
这是
代码FloatConverter.c
1 #ifndef FloatConverterh
2 #define FloatConverterh
3
4 #include "FloatConverter.h"
5 #include <stdint.h>
6
7 #define MAXVALUE 6000
8 union Cast
9 {
10 double d;
11 long l;
12 };
13
14 int32_t float2int(double d)
15 {
16 static volatile Cast cast;
17
18 cast.d = d + 6755399441055744.0;
19 return cast.l;
20 }
21
22 // naive
23 int32_t f32ToInt16Digits(float f32)
24 {
25 return ((int32_t)(f32 * 2 * MAXVALUE/65535)));
26 };
27
28 // improved
29 int32_t f32ToInt16Digits2(float f32)
30 {
31 return (float2int(f32 * 2 * MAXVALUE/65535));
32 };
33
34 #endif
FloatConverter.h
extern int32_t f32ToInt16Digits(float f32);
extern int32_t f32ToInt16Digits2(float f32);
我敢肯定,错误在于包含文件中。如果我删除它(和所有参考),一切都恢复正常和良好。
这是由编译器放出来的错误:
在FloatConverter.c
expected '=', ',', ';', 'asm' or '__attribute__' before 'cast' 16
'cast' undeclared (first use in this function) 16
expected ';' before ')' token 25
expected statement before')' token 25
在FloatConverter.h
:
expected '=', ',', ';', 'asm' or '__attribute__' before 'f32ToInt16Digits' 1
expected '=', ',', ';', 'asm' or '__attribute__' before 'f32ToInt16Digits2' 2
我现在没有任何提示感谢。
为什么在你的函数定义之后有分号?也是* FloatConverter.h *的全部内容?你不使用包括守卫?为什么在执行文件中包含警卫? –
函数定义之后的分号是一个实验,它们不会伤害任何我认为的人。是的,它是整个文件。包含锁定错误,但这不是错误的来源(测试它)。 – anyone