Skip to content

Tech C Programming

Jamie edited this page Jun 3, 2023 · 9 revisions

I like C. You don't have to, but I do.

Here are some useful/interesting/insightful resources which I always refer back to:

Other things I liked:

Building

Arguments

Learning

Networking

Numbers/Memory

SDL

Roguelike Stuff

Rust

DOS

Vim

vim-lsp

https://github.com/prabirshrestha/vim-lsp

This is rad for everything except the kernel.

I use the ccls language server, I've found it better than clangd.

I generate compile_commands.json with bear like bear -- make

Key bindings:

    setlocal signcolumn=no
    if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> gs <plug>(lsp-document-symbol-search)
    nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
    nmap <buffer> gr <plug>(lsp-references)
    nmap <buffer> gi <plug>(lsp-implementation)  " doesn't seem to do anything for C
    nmap <buffer> gt <plug>(lsp-type-definition)
    nmap <buffer> <leader>R <plug>(lsp-rename)
    nmap <buffer> [g <plug>(lsp-previous-diagnostic)
    nmap <buffer> ]g <plug>(lsp-next-diagnostic)
    nmap <buffer> K <plug>(lsp-hover)
    nnoremap <buffer> <expr><c-k> lsp#scroll(+4)
    nnoremap <buffer> <expr><c-j> lsp#scroll(-4)
    nmap <buffer> <f2> <plug>(lsp-rename)

GNU Global's gtags-cscope

For the Linux kernel, I use the source code tagging system GNU Global to generate source code tags (it's much better than ctags), and this ships with a plugin that improves on the old vim-cscope:

https://cvs.savannah.gnu.org/viewvc/global/global/gtags-cscope.vim?revision=1.14&view=markup

There's a bit of history there, this assumes familiarity with cscope concepts:

  • symbol global definition
  • symbol usage
  • symbol callers
  • extended regex search

It creates Vim commands for these:

  • :cs f g SYMBOL
  • :cs f s SYMBOL
  • :cs f c SYMBOL
  • :cs f e PATTERN

It creates leader actions for these when you're on a keyword:

  • Ctrl + leader + g
  • Ctrl + leader + s
  • Ctrl + leader + c
  • Ctrl + leader + e

This is MUCH quicker than constantly hopping in and out of cscope, and lets you use Vim's native jump list commands to navigate older (Ctrl+o) and newer (Ctrl+i) as you read. See :help jump-motions

About

This is a wiki of useful advice I commonly give or have seen on places like StackExchange and Reddit. Sometimes I will link directly to useful posts, sometimes I will make a page on here and curate content.

License

Unless otherwise noted per-page, all information here is provided under Creative Commons - Attribution - Share Alike. Anyone can steal this stuff, but you must give credit and you must provide others the same rights.

Money

If you wish to give a financial thanks for any advice, please do not send me anything. Instead, make a donation to an animal rescue charity or environmental charity in your area.

Clone this wiki locally