Skip to content

Instantly share code, notes, and snippets.

@brunoczim
Created May 23, 2017 14:48
Show Gist options
  • Save brunoczim/2f293fd4dba2672b9a9b2fb7c39c726b to your computer and use it in GitHub Desktop.
Save brunoczim/2f293fd4dba2672b9a9b2fb7c39c726b to your computer and use it in GitHub Desktop.
Prints the size of a given C type in shell (requires gcc, but changes for whatever compiler you use are welcome).
#!/usr/bin/env sh
if [ $# -gt 0 ]
then
CODE="#include <stdio.h>"$'\n'"int main() { printf(\"%lu\n\", sizeof($@)); return 0; }"
echo "$CODE" | gcc -o size -x c - && ./size && rm -f size
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment