Skip to content

Instantly share code, notes, and snippets.

@brunoczim
brunoczim / sizeof.sh
Created May 23, 2017 14:48
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