C没有正确看到我的功能?

时间:2011-07-10 14:29:46

标签: c

我是C的新手。我有一个定义如下的函数:

/*
 * Draws an image in mode3 USING DMA.
 * int x x coordinate 
 * int y y coordinate
 * int width Width of the image (Note may not be the same width as the GBA)
 * int height Height of the image (Note may not be the same height as the GBA)
 * const u16* pointer to the first element in the image
 */
void drawImage3(int x, int y, int width, int height, const u16* image)
{
    int r;
    for (r=0; r<height; r++) {  

            DMA[3].src = &image;
            DMA[3].dst = &videoBuffer[OFFSET(x+width, y, 240)];
            DMA[3].cnt = width | DMA_SOURCE_FIXED| DMA_ON | DMA_DESTINATION_INCREMENT; 
            image = &image + (r * width);

    }

}

在.h文件中,我在主程序中包含了这个:

void drawImage3(int x, int y, int width, int height, const u16* image);

其中u16表示无符号短语,在其他地方定义。

这些也在我的.h文件中:

extern unsigned short *videoBuffer;
extern const unsigned short *pt; 

在另一个h文件中是一个1024个const unsigned short的数组。

在我的main.c文件中,我调用我的函数:

pt = imgArray;
drawImage3(25,25, img_WIDTH, img_HEIGHT, pt);

我收到了很多错误。

Program.c:22: error: data definition has no type or storage class
Program.c:22: error: type defaults to 'int' in declaration of 'pt'
Program.c:22: error: conflicting types for 'pt'
myLib.h:21: note: previous declaration of 'pt' was here
Program.c:22: error: initializer element is not constant
Program.c:23: error: expected declaration specifiers or '...' before numeric constant
Program.c:23: error: expected declaration specifiers or '...' before numeric constant
Program.c:23: error: expected declaration specifiers or '...' before numeric constant
Program.c:23: error: expected declaration specifiers or '...' before numeric constant
Program.c:23: error: expected declaration specifiers or '...' before 'pt'
Program.c:23: error: data definition has no type or storage class
Program.c:23: error: type defaults to 'int' in declaration of 'drawImage3'
Program.c:23: error: conflicting types for 'drawImage3'
myLib.h:117: note: previous declaration of 'drawImage3' was here

有什么想法在这里发生?

------- EDITS

是的,Oli,你对第一个错误是正确的。谢谢!我已经编辑了我的功能,错误消失了。我也做了我的* pt和extern。

Program.c:

//Philip Johnson
#include <stdio.h>
#include "img.h"
#include <unistd.h>
#include "myLib.h"
#include "text.h"

typedef struct        // This typedef defines a new type called MOVOBJ
{                     // which are structures that hold all the info for
    int row;          // a single movable object
    int col;
    int rdel;
    int cdel;
    u16 color;

} MOVOBJ;

MOVOBJ newcharacter, car1, car2, car3;
int size = 5;
int speed = 2;
int checkforend = 0;
pt = imgArray;
drawImage3(25,25, img_WIDTH, img_HEIGHT, pt);
int main(){ //....and so on from there

1 个答案:

答案 0 :(得分:1)

您可能意味着u16* pt = imgArray; - 如果您在C中声明新变量,则必须提供类型。