Re: define_c_func/proc and 64-bit return types

new topic     » goto parent     » topic index » view thread      » older message » newer message

I think I'm on the right track. How does this look? (Functions al_malloc/al_free are just Allegro's wrappers around malloc/free.)

al_shim.h

#include <stdio.h> 
#include <allegro5/allegro.h> 
 
ALLEGRO_COLOR *eu_map_rgba( unsigned int r, unsigned int g, unsigned int b, unsigned int a ); 

al_shim.c

#include <stdio.h> 
#include <allegro5/allegro.h> 
 
#include "al_shim.h" 
 
ALLEGRO_COLOR *eu_map_rgba( unsigned int r, unsigned int g, unsigned int b, unsigned int a ) 
{ 
    ALLEGRO_COLOR *color = al_malloc( sizeof(ALLEGRO_COLOR) ); 
    *color = al_map_rgba( r, g, b, a ); 
 
    return color; 
} 

shimtest.c

#include <stdio.h> 
#include <allegro5/allegro.h> 
 
#include "al_shim.h" 
 
int main( int argc, char **argv ) 
{ 
    if( !al_init() ) { 
        fprintf( stderr, "failed to initialize allegro!\n" ); 
        return -1; 
    } 
 
    ALLEGRO_COLOR *color = eu_map_rgba( 255, 0, 255, 0 ); 
    printf( "color = (%0.3f,%0.3f,%0.3f,%0.3f)\n", color->r, color->g, color->b, color->a ); 
    al_free( color ); 
 
    return 0; 
} 

Output...

color = (1.000,0.000,1.000,0.000) 

Hey look, I'm a C programmer! (I don't do this very often so it's always exciting and/or stressful.) grin

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu