User Tools

Site Tools


c_language:overview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
c_language:overview [2021/03/01 13:12] utedassc_language:overview [2022/09/12 00:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== C Language ======
 +
 ====== Things i should read up on ====== ====== Things i should read up on ======
  
Line 4: Line 6:
   * [[https://en.cppreference.com/w/c/language/eval_order|Evaluation order]]   * [[https://en.cppreference.com/w/c/language/eval_order|Evaluation order]]
   * [[http://c-faq.com/index.html|C FAQ]]   * [[http://c-faq.com/index.html|C FAQ]]
 +  * [[https://www.agner.org/optimize/calling_conventions.pdf|C++ ABI]] -- Not exclusively for C, but still relevant 
 +  * [[https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html|Statements and Declarations in Expressions]] 
 +  * What inline in combination with export and static actually does [[https://stackoverflow.com/questions/6312597/is-inline-without-static-or-extern-ever-useful-in-c99|SO1]], [[https://stackoverflow.com/questions/216510/what-does-extern-inline-do|SO2]], [[https://en.cppreference.com/w/c/language/inline|CPP reference]] 
 +  * [[http://www.catb.org/esr/structure-packing/]] -- The lost art of structure packing
  
 [[http://www.underhanded-c.org/|Underhanded C Contest]] [[http://www.underhanded-c.org/|Underhanded C Contest]]
 +
 +[[http://uguu.org/sources.html|uguu]] -- Anime ascii art
 +====== IOCCC ======
  
 [[https://www.ioccc.org/|The International Obfuscated C Code Contest]] [[https://www.ioccc.org/|The International Obfuscated C Code Contest]]
 +
 +  * [[https://stackoverflow.com/questions/19298778/why-does-the-1987-korn-oneliner-print-unix|Best one-liner 1987]]
 +
 +====== 8 phases of translation in C ======
 +[[https://stackoverflow.com/questions/1476892/poster-with-the-8-phases-of-translation-in-the-c-language/1479972#1479972|stackoverflow]]
 +
 +<code>
 +                       ANSI C translation phases
 +                       =========================
 +
 +          +-------------------------------------------------+
 +          | map physical characters to source character set |
 +          |     replace line terminators with newlines      |
 +          |           decode trigraph sequences             |
 +          +-------------------------------------------------+
 +                                   |
 +                                   V
 +               +---------------------------------------+
 +               | join lines along trailing backslashes |
 +               +---------------------------------------+
 +                                   |
 +                                   V
 +     +-------------------------------------------------------------+
 +     | decompose into preprocessing tokens and whitespace/comments |
 +                          strip comments                         |
 +                          retain newlines                        |
 +     +-------------------------------------------------------------+        
 +                                   |
 +                                   V
 +          +------------------------------------------------+
 +          | execute preprocessing directives/invoke macros |
 +          |              process included files            |
 +          +------------------------------------------------+
 +                                   |
 +                                   V
 +   +----------------------------------------------------------------+
 +   | decode escape sequences in character constants/string literals |
 +   +----------------------------------------------------------------+
 +                                   |
 +                                   V
 +                +--------------------------------------+
 +                | concatenate adjacent string literals |
 +                +--------------------------------------+
 +                                   |
 +                                   V
 +              +------------------------------------------+
 +              | convert preprocessing tokens to C tokens |
 +              |       analyze and translate tokens       |
 +              +------------------------------------------+
 +                                   |
 +                                   V
 +                    +-----------------------------+
 +                    | resolve external references |
 +                    |        link libraries       |
 +                    |      build program image    |
 +                    +-----------------------------+
 +</code>
 ====== Right-to-left rule ====== ====== Right-to-left rule ======
 +[[https://stackoverflow.com/questions/8392228/complicated-right-to-left-rule-when-defining-a-variable|SO thread]]
 +
 +[[https://www.reddit.com/r/learnprogramming/comments/66a4og/the_rightleft_rule_useful_for_understanding_cc/|Reddit]]
 +
 To decode the expression ''char (*(*x())[5])()'' To decode the expression ''char (*(*x())[5])()''
 <code c> <code c>
Line 20: Line 89:
 char (*(*x())[5])() : returning char char (*(*x())[5])() : returning char
 </code> </code>
 +
 +====== Pointer vs Array ======
 +They are NOT the same, despite what people say!
 +
 +<code c>
 +// 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
 +</code>
 +
  
 ====== Const ====== ====== Const ======
Line 27: Line 109:
 const uint8_t *foo; // Same as above. const uint8_t *foo; // Same as above.
 uint8_t *const foo; // Constant pointer. Can't change the address it is holding. uint8_t *const foo; // Constant pointer. Can't change the address it is holding.
 +</code>
 +
 +====== 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.
 +
 +[[https://en.cppreference.com/w/c/types/integer|This site]] lists all available macros and types.
 +
 +<code c>
 +#include <stdint.h>
 +#include <inttypes.h>
 +
 +...
 +
 +  printf("Printing a uint8_t: %" PRIu8 " woop woop!", var8bit);
 </code> </code>
  
c_language/overview.1614604352.txt.gz · Last modified: 2022/09/12 00:30 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki