Skip to content

Instantly share code, notes, and snippets.

@Qix-
Last active September 28, 2015 21:24
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 Qix-/3e5256806e305cb4d0ef to your computer and use it in GitHub Desktop.
Save Qix-/3e5256806e305cb4d0ef to your computer and use it in GitHub Desktop.
Code Docs

Code Docs

Because I'm tired of guessing at consumption, ownership, and lifetimes.

This little collection of snippets can be used in C/C++ projects to help document - in code - the ownership, lifetime, and consumption of arguments (both in signatures and invocation expressions).


The header provided is a set of simple #define statements, allowing the documentation to run.

NOTE: This does impose the limitation that the identifiers uses, owns, and consumes will no longer work in your code!

The provided vim-script can be used for helping discern these keywords in code. You'll want to tweak the color values.

Yes, I know.

This is a documentation "hack", and while it seems that it will cause readability headaches, the benefits of knowing just what code is doing with your pointer is beyond helpful.

License

Released into the public domain by Josh Junon (Qix-). Do what you want with it.

" Code Docs
" https://gist.github.com/Qix-/3e5256806e305cb4d0ef/edit
" Released into the public domain by Josh Junon
" drop this into ~/.vim/bundle/code-docs/after/syntax/c.vim
" and/or ~/.vim/bundle/code-docs/after/syntax/cpp.vim
syntax keyword CodeDoc uses owns consumes
" and in your theme files (or just here, if you fancy dark red):
" hint: ctermfg=XX is a 256-color ANSI color (google it!)
highlight CodeDoc ctermfg=88 guifg=#880000
#ifndef QIX_CODE_DOCS_H__
#define QIX_CODE_DOCS_H__
/*
SITE:
https://gist.github.com/Qix-/3e5256806e305cb4d0ef/edit
Released into the public domain by Josh Junon
USAGE:
int some_function(consumes some_t *aPointer, uses some_t *anotherPointer);
struct some_t {
owns type_t *aPointer;
uses type_t *anotherPointer;
};
*/
#define uses
#define owns
#define consumes
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment