Skip to content

Instantly share code, notes, and snippets.

@duckinator
Created August 19, 2010 00:24
Show Gist options
  • Save duckinator/536641 to your computer and use it in GitHub Desktop.
Save duckinator/536641 to your computer and use it in GitHub Desktop.
#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