Created
August 19, 2010 00:24
-
-
Save duckinator/536641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#define new(TYPE, ARGS...) ({\ | |
TYPE *item = ( TYPE *)malloc(sizeof( TYPE )); \ | |
*item = ( TYPE ){ ARGS }; \ | |
item; \ | |
}) | |
typedef struct { | |
int scancode; | |
int shift; | |
int control; | |
} KeyEvent; | |
int main() | |
{ | |
/*KeyEvent* a = malloc(sizeof(KeyEvent)); | |
*a = (KeyEvent){ .scancode = 1, .shift = 2, .control = 3 };*/ | |
KeyEvent* a = new(KeyEvent, .scancode = 1, .shift = 2, .control = 3); | |
KeyEvent* b = new(KeyEvent, 1, 2, 3); | |
printf("scancode = %i, shift = %i, control = %i\n", a->scancode, a->shift, a->control); | |
printf("scancode = %i, shift = %i, control = %i\n", b->scancode, b->shift, b->control); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment