3854Fermer3856
FarewellLe 26/10/2014 à 21:02
Oui mais non, j'ai malheureusement c/c le header avec des modifs en cours, j'en fais 50/minute depuis 1/2 heure. Le "véritable header", c'est ça :
header
#ifndef BUTTON_H #define BUTTON_H #include <stdbool.h> #include <SDL2/SDL.h> #include "ContextHelp.h" #define BUTTON_ENABLED true #define BUTTON_DISABLED false struct BUTTON; typedef bool (*button_MouseIn)(struct BUTTON* button); typedef bool (*button_MouseOut)(struct BUTTON* button); typedef bool (*button_LeftClick)(struct BUTTON* button); typedef struct { SDL_Texture* SprEnabled; // Cannot be NULL SDL_Texture* SprDisabled; // May be NULL SDL_Texture* SprClicked; // May be NULL // button_MouseIn in; // May be NULL button_MouseOut out; // May be NULL button_LeftClick leftclick; // Cannot be NULL. Will be triggered on clic // bool enabled; // Button is not affected by the mouse if enabled is false /* * Internal */ int mouse_status; // Status of the mouse over the button SDL_Rect dest; // Destination location and size of the button SDL_Texture* sprite; // The sprite currently used CONTEXT_HELP* context; // Current help context SDL_Texture* help; // The texture given to the context help handler } BUTTON; #define STATUS_MOUSE_OUT 0 #define STATUS_MOUSE_IN 1 #define STATUS_CLICK_LEFT_DOWN 2 #define STATUS_CLICK_LEFT_UP 3 bool ButtonInit (BUTTON* button, char* SprEnabled, char* SprDisabled, char* SprClicked, int x, int y, bool enabled, button_MouseIn in, button_MouseOut out, button_LeftClick leftclick, char* help, CONTEXT_HELP* context); void ButtonClose (BUTTON* button); bool ButtonUpdate (BUTTON* button, SDL_Event* event, int mouse_x, int mouse_y); bool ButtonDraw (BUTTON* button); #endif // BUTTON_H

Et là tu peux vérifier, pas de struct intempestif qui traine.

Et voici un test case :struct struct_t; typedef void (*callback_t) (struct struct_t* arg); typedef struct { callback_t cb; } struct_t; void cb (struct_t* arg) { (void) arg; } int main (void) { struct_t s; s.cb (&s); return 0; }
$ gcc -W -Wall test.c -o test
test.c: In function ‘main’:
test.c:20:9: warning: passing argument 1 of ‘s.cb’ from incompatible pointer type
   s.cb (&s);
         ^
test.c:20:9: note: expected ‘struct struct_t *’ but argument is of type ‘struct struct_t *’

Peut-être que je me plante en grand, mais je suis très preneur d'une solution...