c_language:overview
This is an old revision of the document!
Table of Contents
C Language
Things i should read up on
- C++ ABI – Not exclusively for C, but still relevant
IOCCC
Right-to-left rule
To decode the expression char (*(*x())[5])()
x : x is a x() : function *x() : returning pointer to (*x())[5] : a 5-element array of *(*x())[5] : pointer to (*(*x())[5])() : function char (*(*x())[5])() : returning char
Pointer vs Array
They are NOT the same, despite what people say!
// Example of char array vs char pointer char *str1 = "Foo"; // Pointer. "Foo" resides in TEXT-section char str2[] = "Bar"; // Array. "Bar" resides in RAM, copied to DATA section during C-startup str1[2] = 'O'; // Illegal, undefined behaviour str2[2] = 'R'; // This is fine, it alters content of RAM
Const
uint8_t const *foo; // Points at constant. Can't change the value that foo points at. const uint8_t *foo; // Same as above. uint8_t *const foo; // Constant pointer. Can't change the address it is holding.
stdint.h, printf and scanf
stdint.h has definitions of uint8_t etc.
inttypes.h has definitions of PRIu8 etc, for use with printf and scanf.
This site lists all available macros and types.
#include <stdint.h> #include <inttypes.h> ... printf("Printing a uint8_t: %" PRIu8 " woop woop!", var8bit);
Snippets
Debug macro
#define STRINGIFY_(X) #X #define STRINGIFY(X) STRINGIFY_(X) #define PING() debug_print_str(__FILE__ " : " STRINGIFY(__LINE__) "\n")
c_language/overview.1623151053.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
