Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created April 29, 2015 03:27
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/6a2782c58e779ff889aa to your computer and use it in GitHub Desktop.
Save JadenGeller/6a2782c58e779ff889aa to your computer and use it in GitHub Desktop.
C Type Inference (Let and Var)
#define let(name,value) const __typeof__ (value) name = value;
#define var(name,value) __typeof__ (value) name = value;
int main(int argc, char *argv[]) {
let(x,3); // const int x = 3;
var(y,5); // int y = 5;
printf("x:%i y:%i",x,y); // -> x:3 y:5
}
@dannyflax
Copy link

Pretty cool how you've turned some higher-level functionality into usable C macros. Much appreciated!

@alexispurslane
Copy link

Super awesome dude!

@pronesto
Copy link

pronesto commented Nov 3, 2016

Hi Jaden, we have a type inference engine to C, which is able to reconstruct some types not available in the source code. Check it out: http://cuda.dcc.ufmg.br/psyche-c/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment