Skip to content

Instantly share code, notes, and snippets.

@hgiesel
Last active November 4, 2016 03:12
Show Gist options
  • Save hgiesel/a3cb0e626c882662d728b80b204f2e23 to your computer and use it in GitHub Desktop.
Save hgiesel/a3cb0e626c882662d728b80b204f2e23 to your computer and use it in GitHub Desktop.
Programming Links and Insights

Phases

Preprocessing phase
  • basic source character set (no `$@) translated to universal character name (\u + \U)
  • (trigraph sequences)
  • <newline> at the end of the line are removed (single pass)
  • decomposed into comments and preprocessing tokens:
    • header names, identifiers, numbers, literals, etc.
    • operators + punctuators
  • transformations inside double quotes are reverted
  • each comment replaced by a single space
  • preprocessor executed -> all preprocessor tokens are removed
Compilation phase
  • literals are converted from source character set to execution character set
  • adjacent string literals are concatenated
  • ��compilation executed (syntactic analyzation and semantic analyzation)
Linking phase
  • each TU examined to procude list of template instantiations
  • definitions of templates and required instantiants are perfromed to produce instantiation units (IU)
  • TUs, IUs, and libraries needed to satisfy external references are collected into program image
  • linking takes place

Clang compilation

  • -target-cpu core2

  • -target-linker-version 253.9

  • -dwarf-column-info

  • -fdebug-compiliation-dir $CURDIR

  • -ferror-limit "19"

  • -fmessage-length "135"

  • -munwind-tables

  • -mrelax-all

  • -mrelocation model pic -pic_level

  • -mthread-model posix

  • -mdisable-fp-elim

  • -masm-verbose

  • -Wdeprecated=obj-isa-usage

  • -Werror=obj-isa-usage

  • -main-file-name 'a.c'

Clang++ compilation

    • -lc++
    • -stdlib=c++
    • -fdeprecated=macro
    • -fcxx_exception
    • -fexceptions
  • -E : preprocessing

  • -f : syntax only

  • -S : assembly code (GA)

  • -c : normal compilation

Differences between C and C++

  1. implicit assignment from void* in C in C: always cast the result to the corresponding type (e.g. int *ptr = (int*) malloc(sizeof(int)); )
  2. string literals are char[] in C, char const[] in C++ in C: always assign string literals to char const[], instead of char[]
  3. new + new[] instead of malloc, calloc, etc. Nothing you can do about it, avoid malloc in C++
  4. necessity of declaration of function before use in C++ do that in C as well
  5. typedef vs. using
  6. always return from main -> it's just a function!
  7. in C, main is callable from other functions, but don't do it
  8. don't skip initializations in C
  9. Avoid tentative definitions in C
  10. Don't declare tags in C function prototypes
  11. don't cast implicit const to non-const
  12. always initialize const values (not necessary in C++)
  13. char constant int in C, char in C++
  14. const globals are file scope in C, not in C++

clang shared libraries

  • @executable_path: relative to directory of main executable
  • @loader_path: relative to referring library -> for plug-ins
  • @rpath: relative to any list of paths which are passed as arguments when compiling (-rpath)

Linux

pthread_mutex_t _init _lock _unlock _destroy _trylock

pthread_condattr _init _destroy pthread_cond _init _destroy _signal _wait _timedwait _broadcast

rwlock _init _destroy _rdlock _wrlock _tryrdlock _trywrlock _unlock

each INODE consists of:

  • file type (regular file, directory, block device file, etc.)
  • number of hardlinks associated
  • file length in bytes
  • device ID
  • inode that identifies the file
  • UID
  • GID
  • atime, mtime and ctime
  • access rights + file mode

apt-cache

  • stats: shows general stats about pkgs
  • gencaches: build both package and source
  • show: show a readable record for package
  • showpkg: show general information for pkg
  • showsrc: show source records
  • search
  • depends: all dependencies
  • rdepends: all reverse dependencies
  • unmet: all unmet depen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment