Skip to content

Instantly share code, notes, and snippets.

@wtnb75
Created July 17, 2014 13:26
Show Gist options
  • Save wtnb75/800697b760853317cd67 to your computer and use it in GitHub Desktop.
Save wtnb75/800697b760853317cd67 to your computer and use it in GitHub Desktop.
#! /bin/sh
CC=${CC-gcc}
lang=${lang-c}
incfs=()
structs=()
for i; do
if [ -f "$i" ] ; then
incfs+=("$i")
elif [ "$i" != "${i%.h}" -o "$i" != "${i%.hpp}" -o "$i" != "${i#<}" ] ; then
incfs+=("$i")
else
structs+=("$i")
fi
done
tmpf=$(mktemp -t /tmp)
(
echo "#include <stdio.h>"
for((l=0;l<${#incfs[@]}; ++l)); do
if [ "${incfs[$l]}" != "${incfs[$l]#<}" ] ; then
echo "#include ${incfs[$l]}"
else
echo "#include \"${incfs[$l]}\""
fi
done
echo "int main(int argc, char **argv){"
for((l=0;l<${#structs[@]}; ++l)); do
echo "printf(\"sizeof(${structs[$l]})=%lu\\\\n\", sizeof(${structs[$l]}));"
done
echo "return 0;}"
) > $tmpf
${CC} -x $lang $tmpf -o ${tmpf}.exe
[ -x ${tmpf}.exe ] && ${tmpf}.exe
rm -f $tmpf ${tmpf}.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment