2015-10-13 99 views
1

我正在使用C語言使用IAR Embedded Workbench。聲明不兼容

我在將項目劃分爲通常的main/.h/.c格式時遇到了一些麻煩。

例如,如果我創建一個example.h文件

#ifndef EXAMPLE_H 
#define EXAMPLE_H 
void function(int [], int); 
#endif 

而不是example.c

#include "example.h" 
void function (int[] array, int number) 
{number = 1; //code 
} 

它說:

Error[Pe147]: declaration is incompatible with "__interwork __softfp 
void function(int *, int)" (declared at line 4 of (path) 

Error[Pe141]: unnamed prototyped parameters not allowed when body is  present (path) 


Error[Pe020]: identifier "number" is undefined (path) 

Error while running C/C++ Compiler 
+0

'int [] array' ???這是C,而不是Java!另外,你說你正在使用「通常的.h/.c格式」,那麼你在C文件中的哪個位置包含相應的H文件? –

+1

當然不是。但這不是告訴它的方式。冷靜下來。對於c文件,看看。 – EagleOne

+0

在'example.h'中你不需要使用'#ifndef EXAMPLE_H',只要你喜歡,你可以多次聲明一個函數原型,只要它們都是一樣的。 –

回答

2

你用錯誤的語法。看看

void function (int array[], int number) 
{ number = 1; //code 
} 
3

問題出在void function(int [], int)。更改爲void function(int name[], int)void function(int *, int)。另一個錯誤是在int[] array - 它必須是int array[]int * array

+0

'void function(int [],int);'不是問題。這實際上是有效的C. – cremno

相關問題