(or emacs irrelevant)

GCC macros and auto-yasnippet

As one thing leads to another, it occurred to me that I didn't know what __GNUC__ macro does. Which brought me to the manual page on Common Predefined Macros.

Using org-mode Babel to check the macro values

I decided that just skimming through the page wasn't enough, and I wanted to brush up on my org-mode babel. So I created this wiki page to which you're welcome if you ever need to check __BYTE_ORDER_ or __UINT_FAST16_TYPE__ on your system.

Here's a small excerpt of it:

#+begin_src C :results verbatim
#include <stdio.h>

int main() {
  // version stuff
  printf("__GNUC__ %d\n", __GNUC__);
  printf("__GNUC_MINOR__ %d\n", __GNUC_MINOR__);
  printf("__GNUC_PATCHLEVEL__ %d\n", __GNUC_PATCHLEVEL__);
  printf("__VERSION__ %s\n", __VERSION__);
  return 0;
}
#+end_src

When you navigate to any place in the code and press C-c C-c, which calls (sic) org-ctrl-c-ctrl-c, it will re-compile and re-run your program.

I list here some of the config to make it all work:

(org-babel-do-load-languages
 'org-babel-load-languages
 '((C . t)
   ;; ...
   ))

(setq org-babel-C-compiler "gcc -std=c99")

New auto-yasnippet method

You can read up on what auto-yasnippet is in this post. For the wiki page, I had to insert the printf statements a bunch of times, some of them with triply-repeated symbols. Take, for instance, this statement:

printf("__INT32_TYPE__ %s (%d)\n", ESTR(__INT32_TYPE__), sizeof(__INT32_TYPE__));

With the old method, I would insert ~ before each INT32 and call aya-create. But it would result in this snippet, which isn't optimal:

printf("__$1 %s (%d)\\n", ESTR(__$1), sizeof(__$1));

With the new method (the old one still works, it's just that the new one takes priority), I would only quote the first field like so:

printf("__`INT32'_TYPE__ %s (%d)\n", ESTR(__INT32_TYPE__), sizeof(__INT32_TYPE__));

Which results in this snippet:

printf("__$1_TYPE__ %s (%d)\n", ESTR(__$1_TYPE__), sizeof(__$1_TYPE__));

Much better.

oremacs wiki workflow

If you're crazy enough (in a good way) to follow oremacs, you'll get the new wiki page delivered right to your config with

make install

which will also update to the latest org-mode and CEDET.

And here's how to access it:

  • run xmodmap etc/.Xmodmap to make ; into a modifier
  • press ;-k to open a dispatch hydra
  • press w to select the wiki
  • select C (currently, the only other candidate is git)

Outro

Check out the new auto-yasnippet method, I think it's pretty efficient. I hope that you'll find the wiki page useful in your C pursuits. And a big thanks to Eric Schulte for org-babel.