C NoteC Learning Markdown C Learning Markdown

C Learning Markdown

  • Syntax:
    • Lexical elements:
      • identifier: start with [_a-zA-Z], and makeup with [_a-zA-Z0-9].
      • keyword:
          auto, break, case, char, const, continue, default, do, double,
          else, enum, extern, float, for, goto, if, int, long, register,
          return, short, signed, sizeof, static, struct, switch, typedef,
          union, unsigned, void, volatile, while, inline, restrict, _Alignas,
          _Alignof, _Atomic, _Bool, _Complex, _Generic, _Imaginary,
          _Noreturn, _Static_assert, _Thread_local.
        
      • constant: integer, floating point, character, enumerated type, “str”.
      • operator:
          total:
          var++, var--, array[], func(), (expr), obj.data, ptr->data,
          (type){list}, -minus, (type), ++var, --var, *ptr, &var, !expr,
          ~var, sizeof, _Alignof, /, *, %, +, -, <<, >>, >, >=, <, <=, ==,
          !=, &, ^, |, &&, ||, ?:, =, /=, *=, %=, +=, -=, <<=, >>=, &=, ^=,
          |=, ,.
        
          sort:
              + assignment:=, /=, *=, %=, +=, -=, <<=, >>=, &=, ^=, |=. 
              + (in|d)cement: var++, var--, ++var, --var.
              + arithmetic: +var -var + - * / % ~ & | ^ << >>.
              + logical: !expr, ||, &&.
              + comparision: >, >=, <, <=, ==, !=.
              + member access: a[b], *a, &a, a->b, a.b.
              + others: a(...), a,b , (type)a, ?:, sizeof, _Alignof.
        
      • delimeter: white space characters, and comment characters, //, /* */.
    • Syntax elements:
      • type:
          [auto|register|static|extern|typedef] [const|volatile] 
              [signed|unsigned] (void|char|int|short|long|float|double) [*]
          [typedef] (struct|union) [identifier] { ... }[*]
          [typedef] enum [identifier] { ... }
          type (*array_id)[]
          rt_type (*func_id)(arg_type arg_id,..)
        
      • expression:
          [operator] (identifier|constant|string) [operator]
        
      • statement:
          label_id: statement;
          case const_expr: statement;
          default: statement;
        
          expr;
        
          { decalaration statement }
        
          if(expr) statement [else statement]
          switch(expr) statement
        
          while(expr) statement
          do statement while(expr);
          for(expr; expr; expr) statement
        
          goto label_id;
          continue;
          break;
          return [expr];
        
      • decalaration:
          type var_id;
          type array_id[];
          rt_type func_id(arg_type arg_id, ...);
        
      • scope:
          storage:
               + auto: auto, register;
               + static: static;
          link: static, extern;
        
      • data access:
          normal: var_id.
          pointer: &var_id, *ptr.
          array: array_id[index], *(array_id + index).
          struct and union: obj.data, p_obj->data.
          function: func_id(arg_list).
        
    • Others:
      • preprocess: text replace, condition replace, and include header files.
      • template: no, use preprocessor macro to realize.
      • namespace: no, use unique identifier name.
  • Feature:
    • Paradigm: static compiling , procedural programming language.
    • (Package|Library) managment: use preprocessor to include header files,
      after compiling then link with library.
    • OOP: no
    • FP: no
    • GC: no
    • VM: no
    • Thread: by library.
    • Misc:
      • Pointer is memory address with type infomation.
      • Array is a ptr with length info, and function is a ptr with args info.
      • Array as an argument will pass array name as a pointer without length info.
      • Array index start from 0.
      • char[] can not be change, so you need to decalare it as const.
      • Auto convert type from low precision to high precision.
      • A function can return only one value.
      • Call function should with explicit type, numbers of arguments.
      • Operators has precedence.
      • Use greedy lexcial analysis when evaluate an expression.
      • In the same scope, identifier should be unique, including function name.
      • Use struct, union to create new type, use enum to define constant var.
  • Library:
    • Standard library:
        <assert.h> Conditionally compiled macro that compares its argument to zero
        <complex.h> (since C99) Complex number arithmetic
        <ctype.h> Functions to determine the type contained in character data
        <errno.h> Macros reporting error conditions
        <fenv.h> (since C99) Floating-point environment
        <float.h> Limits of float types
        <inttypes.h> (since C99) Format conversion of integer types
        <iso646.h> (since C95) Alternative operator spellings
        <limits.h> Sizes of basic types
        <locale.h> Localization utilities
        <math.h> Common mathematics functions
        <setjmp.h> Nonlocal jumps
        <signal.h> Signal handling
        <stdalign.h> (since C11) alignas and alignof convenience macros
        <stdarg.h> Variable arguments
        <stdatomic.h> (since C11) Atomic types
        <stdbool.h> (since C99) Boolean type
        <stddef.h> Common macro definitions
        <stdint.h> (since C99) Fixed-width integer types
        <stdio.h> Input/output
        <stdlib.h> General utilities: memory management, program utilities, string conversions, random numbers
        <stdnoreturn.h> (since C11) noreturn convenience macros
        <string.h> String handling
        <tgmath.h> (since C99) Type-generic math (macros wrapping math.h and complex.h)
        <threads.h> (since C11) Thread library
        <time.h> Time/date utilities
        <uchar.h> (since C11) UTF-16 and UTF-32 character utilities
        <wchar.h> (since C95) Extended multibyte and wide character utilities
        <wctype.h> (since C95) Wide character classification and mapping utilities
      
    • Third-party library