2011-07-10 5 views
-3

Im nouveau à C. J'ai une fonction définie en tant que telle:C ne voit pas ma fonction correctement?

/* 
* 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); 

    } 

} 

Dans un fichier .h j'inclure dans mon programme principal, j'ai ceci:

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

où u16 signifie un court non signé et est défini ailleurs.

Et ceux-ci, aussi, sont dans mon dossier .h:

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

dans un autre fichier h est un tableau de 1024 const short non signés.

Dans mon fichier main.c j'appelle ma fonction comme ceci:

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

Je reçois beaucoup d'erreurs.

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 

Une idée de ce qui se passe ici?

------- Permet de modifier

Oui, Oli, vous avez raison de la première erreur. Merci! J'ai édité ma fonction en tant que telle et cette erreur est partie. J'ai aussi fait mon * pt et 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 
+2

Ce n'est pas la première erreur due au même problème que dans [votre question précédente] (http://stackoverflow.com/questions/6639256/pointer-to-first-element-in-array-c)? –

+0

Veuillez poster la première partie de votre fichier main.c. – Perception

+0

En outre, déclarer des variables non -externes dans un fichier d'en-tête est généralement une mauvaise idée. –

Répondre

1

Vous voulez dire probablement u16* pt = imgArray; - si vous déclarer de nouvelles variables en C, vous devez donner le type.

Questions connexes