C

last edited Sat, 29 Mar 2025 06:59:24 GMT
backlinks: null


C

This page does not cover topics relevant to C Plus Plus. Often dubbed a general-purpose or system programming language due to its close associated with the UNIX system.

How to C in 2016 direct link to this section

Modern solutions to modern problems in a not so modern programming language.[1]

  1. Don't write C if you can avoid it, follow modern rules if you must write C
  2. use standard types, not primitive types
    #include <stdint.h>
    
    • char is not included due to misuse
      • acceptable if pre-existing APIs requuire char
    • fast and least types
    • int can be 16bits on some paltforms aand 32 bits on others, good luck edge testing every case if you choose to use int
      • okay if using a function with native return types
  3. never use anything unsigned when <stdint.h> is superior
  4. use intptr_t for system dependent types
  5. declare your for loop counters in-line
  6. #pragma once so headers only need to be included once
  7. allow for static initialiation of auto-allocated arrays and structs
  8. use clang-format
  9. never use malloc, use calloc for performance impact [2]

Libraries direct link to this section

GNU C Library direct link to this section

Commonly referred to as glibc. Supports C++ and other languages.

MUSL direct link to this section

Another common implementation using the MIT license

Compiling direct link to this section

gcc -o p ./p.c

References direct link to this section


  1. How to C ↩︎

  2. The C Programming Language 2nd Edition by Brian W. Kernighan & Dennis M. Richie ↩︎