我繼續無法在以下(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