Skip to content

Instantly share code, notes, and snippets.

@M4GNV5
Created April 7, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M4GNV5/cb8184b0a89f782a6a2f3af1f409c3dd to your computer and use it in GitHub Desktop.
Save M4GNV5/cb8184b0a89f782a6a2f3af1f409c3dd to your computer and use it in GitHub Desktop.
#!/bin/bash
printf "#include <stdio.h>\n" > /tmp/cppmacro.c
while [ $# -gt 1 ]; do
printf "#include <$1.h>\n" >> /tmp/cppmacro.c
shift
done
printf "int main()\n{\n\tprintf(\"%%d\\\\n\", $1);\n\treturn 0;\n}" >> /tmp/cppmacro.c
gcc -D_GNU_SOURCE /tmp/cppmacro.c -o /tmp/cppmacro
/tmp/cppmacro
#!/bin/bash
printf "#include <stdio.h>\n#include <stddef.h>\n" > /tmp/structoffset.c
while [ $# -gt 2 ]; do
printf "#include <$1.h>\n" >> /tmp/structoffset.c
shift
done
printf "int main()\n{\n\tprintf(\"%%d\\\\n\", offsetof($1, $2));\n\treturn 0;\n}" >> /tmp/structoffset.c
gcc -D_GNU_SOURCE /tmp/structoffset.c -o /tmp/structoffset
/tmp/structoffset
#!/bin/bash
printf "#include <stdio.h>\n" > /tmp/structsize.c
while [ $# -gt 1 ]; do
printf "#include <$1.h>\n" >> /tmp/structsize.c
shift
done
printf "int main()\n{\n\tprintf(\"%%d\\\\n\", sizeof($1));\n\treturn 0;\n}" >> /tmp/structsize.c
gcc -D_GNU_SOURCE /tmp/structsize.c -o /tmp/structsize
/tmp/structsize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment