mirror of
https://github.com/libretro/cpp-cheat.git
synced 2025-04-03 03:12:24 +00:00
Markdown style.
This commit is contained in:
parent
74a6cc0b53
commit
b8dc8a4a7e
@ -1,10 +1,12 @@
|
||||
# C++ Cheat
|
||||
|
||||
C and C++ information, cheatsheets and mini-projects.
|
||||
|
||||
[](https://travis-ci.org/cirosantilli/cpp)
|
||||
|
||||
Relies on <https://github.com/cirosantilli/cpp-boilerplate> to factor code out. See [its documentation](https://github.com/cirosantilli/cpp-boilerplate/blob/master/README.md) for information on how to use this project.
|
||||
|
||||
# Most useful files
|
||||
## Most useful files
|
||||
|
||||
- [c.c](c.c): C cheatsheet.
|
||||
- [cpp.cpp](main_cpp.cpp): C++ cheatsheet.
|
||||
@ -12,7 +14,7 @@ Relies on <https://github.com/cirosantilli/cpp-boilerplate> to factor code out.
|
||||
- [opengl/](opengl/)
|
||||
- [kde/](kde/)
|
||||
|
||||
# Quickstart
|
||||
## Quickstart
|
||||
|
||||
On Ubuntu 12.04:
|
||||
|
||||
@ -41,7 +43,7 @@ To get help on all options use:
|
||||
|
||||
make help
|
||||
|
||||
# About
|
||||
## About
|
||||
|
||||
Larger projects may be in separate repositories.
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Boost
|
||||
|
||||
Boost is the most important C++ utilities library.
|
||||
|
||||
It has very widespread use, and some of its features have been included or are candidates for inclusion on newer versions of the stdlib.
|
||||
|
@ -1,8 +1,10 @@
|
||||
# Flex and Bison
|
||||
|
||||
Parser generators.
|
||||
|
||||
Flex and Bison are GNU open source clones of Lex and Yacc respectively.
|
||||
|
||||
#Flex
|
||||
## Flex
|
||||
|
||||
Tokenizer: splits input with regexes.
|
||||
|
||||
@ -11,12 +13,12 @@ Why it works well with bison:
|
||||
- this step is `O(n)`.
|
||||
- the Bison naive algorithm is `O(n^3)`. Theoretical bounds are linked to matrix multiplication at O(n^2.40) and falling, but Bison is likely to
|
||||
|
||||
#Bison
|
||||
## Bison
|
||||
|
||||
Parses deterministic context free languages, AKA deterministic LR.
|
||||
|
||||
Subset of context-free, superset of regex.
|
||||
|
||||
#Sources
|
||||
## Sources
|
||||
|
||||
Very good intro source: [Tom Niemann - Lex & Yacc Tutorial](http://epaperpress.com/lexandyacc/)
|
||||
|
@ -1,10 +1,12 @@
|
||||
# Bison
|
||||
|
||||
Main Bison cheat.
|
||||
|
||||
It is hard to test Bison without Flex, so they are used together.
|
||||
|
||||
Information on Flex is not given here.
|
||||
|
||||
#What the it does
|
||||
## What the it does
|
||||
|
||||
This generates a simple C-like calculator which supports:
|
||||
|
||||
@ -44,7 +46,7 @@ Missing features:
|
||||
- functions
|
||||
- strings
|
||||
|
||||
#cudos
|
||||
## cudos
|
||||
|
||||
This was taken this from a very good intro source:
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Flex with C++
|
||||
|
||||
Example of how to use Flex/Yacc with C++.
|
||||
|
||||
Original source: <http://alumni.cs.ucr.edu/~lgao/teaching/flex.html>.
|
||||
|
@ -1 +1,3 @@
|
||||
# Flex
|
||||
|
||||
Main cheat on Flex. Demonstrates Flex without Bison.
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Fortran
|
||||
|
||||
Fortran cheatsheet.
|
||||
|
||||
Works with the same Makefile as the C one, but put here because people who already have C C++ compilers will want to run without installing anything.
|
||||
|
@ -1,4 +1,6 @@
|
||||
Information about `gcc` and `g++`.
|
||||
# GCC
|
||||
|
||||
Information about the Gnu Compile Collection (GCC), and in particular `gcc` and `g++`.
|
||||
|
||||
[main.c](main.c): `gcc` extensions to the ANSI C language.
|
||||
|
||||
@ -8,16 +10,16 @@ GCC stands for GNU Compiler Collection: *not* C compiler, and currently compiles
|
||||
|
||||
`gcc` and `g++` are the dominant compilers on Linux. Important alternatives include `clang` and Intel's `icc`.
|
||||
|
||||
#g++ vs gcc
|
||||
## g++ vs gcc
|
||||
|
||||
g++: <http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc>
|
||||
`g++`: <http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc>
|
||||
|
||||
Most important:
|
||||
|
||||
1. `g++` treats both `.c` and `.cpp` files as C++, since `.c` is backwards compatible with C++, it works
|
||||
2. `g++` links to (but does not include) stdlib automatically, `gcc` does not!
|
||||
|
||||
#Supported executable formats
|
||||
## Supported executable formats
|
||||
|
||||
- elf (linux)
|
||||
- mach-o (mac os)
|
||||
@ -25,7 +27,7 @@ Most important:
|
||||
|
||||
and more.
|
||||
|
||||
#Compilation steps
|
||||
## Compilation steps
|
||||
|
||||
It is good to understand which steps are done towards compilation
|
||||
|
||||
@ -72,9 +74,9 @@ Does all above steps in one
|
||||
|
||||
If you use make, it is faster to generate `.o` and keep them, since if the source does not change, make will not recompile the corresponding `.o`
|
||||
|
||||
#Flags
|
||||
## Flags
|
||||
|
||||
##Recommended compilation flags
|
||||
### Recommended compilation flags
|
||||
|
||||
Good discussion: <http://stackoverflow.com/questions/154630/recommended-gcc-warning-options-for-c>
|
||||
|
||||
@ -86,7 +88,7 @@ This will make for portable, efficient code.
|
||||
|
||||
For test code, omit the `-03`, since that will make compilation faster.
|
||||
|
||||
##o
|
||||
### o
|
||||
|
||||
Output destination.
|
||||
|
||||
@ -94,7 +96,7 @@ Default: `a.out`.
|
||||
|
||||
For stdout: `-o -`.
|
||||
|
||||
##Wall
|
||||
### Wall
|
||||
|
||||
Enables many useful warnings:
|
||||
|
||||
@ -102,13 +104,13 @@ Enables many useful warnings:
|
||||
|
||||
Understanding each warning and being able to write warning free code is a good way to improve language skills.
|
||||
|
||||
##Wextra
|
||||
### Wextra
|
||||
|
||||
Enables even more useful warnings than wall.
|
||||
|
||||
`gcc -Wextra`
|
||||
|
||||
##std
|
||||
### std
|
||||
|
||||
Specifies the language to be used.
|
||||
|
||||
@ -128,7 +130,7 @@ To allow gnu extensions:
|
||||
|
||||
This is necessary on projects that rely on the extensions, such as the Linux kernel.
|
||||
|
||||
##ansi
|
||||
### ansi
|
||||
|
||||
Don't use this, use `std` instead:
|
||||
|
||||
@ -142,7 +144,7 @@ Changes with time, currently equals:
|
||||
|
||||
It is a bit confusing not to have a fixed version of the standard to comply to, so just use std instead.
|
||||
|
||||
##pedantic
|
||||
### pedantic
|
||||
|
||||
Give warnings for code that does not comply with `c1x` standard:
|
||||
|
||||
@ -156,7 +158,7 @@ Give errors instead of warnings:
|
||||
|
||||
gcc -std=c1x -pedantic-errors
|
||||
|
||||
##march
|
||||
### march
|
||||
|
||||
Optimizes code to given CPU (arch is for archtecture).
|
||||
|
||||
@ -174,7 +176,7 @@ Arm v.7, used on mobiles today:
|
||||
|
||||
gcc -march=armv7
|
||||
|
||||
##Optimization
|
||||
### Optimization
|
||||
|
||||
List possible optimizations for `-O`:
|
||||
|
||||
@ -196,7 +198,7 @@ Best general code optimization method:
|
||||
|
||||
Always use this for production code.
|
||||
|
||||
##debugging
|
||||
### debugging
|
||||
|
||||
GCC has options that allow you to add debugging information to binary outputs.
|
||||
|
||||
@ -212,7 +214,7 @@ Options:
|
||||
- `ggdb`: adds more info
|
||||
- `ggdb3`: adds max info. Default if 2 when ggdb is used.
|
||||
|
||||
##M
|
||||
### M
|
||||
|
||||
Don't compile, but generate a list of dependencies for the given source code in a format suitable for a makefile rule, and output it to stdout.
|
||||
|
||||
@ -245,7 +247,7 @@ You can then use those on a makefile as:
|
||||
$(shell gcc -MM a.c)
|
||||
gcc a.c
|
||||
|
||||
##assembly code
|
||||
### assembly code
|
||||
|
||||
If you want to interpret assembly code generated by `gcc`, the best combo is:
|
||||
|
||||
@ -260,7 +262,7 @@ or:
|
||||
gcc -ggdb3 -o a.o a.c
|
||||
objdump -S a.o
|
||||
|
||||
###-S
|
||||
#### -S
|
||||
|
||||
Generate assembly code:
|
||||
|
||||
@ -268,7 +270,7 @@ Generate assembly code:
|
||||
|
||||
Generates gas assembly code to a new file called `a.S`.
|
||||
|
||||
##-fverbose-asm
|
||||
### -fverbose-asm
|
||||
|
||||
Outputs comments on the generated assembly which say variable names are being operated on each statement:
|
||||
|
||||
@ -291,11 +293,11 @@ With `-fverbose-asm`:
|
||||
movl -64(%ebp), %eax #i, tmp123
|
||||
movl %eax, -68(%ebp) #tmp123, j
|
||||
|
||||
##-f options
|
||||
### -f options
|
||||
|
||||
TODO What are the `-f` options for in general? Give examples.
|
||||
|
||||
##-Wa options
|
||||
### -Wa options
|
||||
|
||||
Same as `-Xassembler`.
|
||||
|
||||
@ -304,7 +306,7 @@ Example:
|
||||
gcc -c -fverbose-asm -Wa,-adhln a.c
|
||||
|
||||
|
||||
##-Xassembler
|
||||
### -Xassembler
|
||||
|
||||
Pass options directly to the `as` assembler.
|
||||
|
||||
@ -312,13 +314,13 @@ Example:
|
||||
|
||||
gcc -c -fverbose-asm -Xassembler -adhln a.c
|
||||
|
||||
#Preprocessor
|
||||
## Preprocessor
|
||||
|
||||
The executable is called `cpp`.
|
||||
|
||||
GCC uses it as a backend.
|
||||
|
||||
##-D
|
||||
### -D option
|
||||
|
||||
Make preprocessor defines command line.
|
||||
|
||||
@ -333,7 +335,7 @@ which is the same as adding:
|
||||
|
||||
to the top of file.
|
||||
|
||||
##find include search path
|
||||
### find include search path
|
||||
|
||||
echo '' | cpp -v
|
||||
|
||||
@ -342,7 +344,7 @@ Look at sections:
|
||||
- `include "..." search starts here`:
|
||||
- `include <...> search starts here`:
|
||||
|
||||
###-I
|
||||
#### -I option
|
||||
|
||||
Append to the include search path:
|
||||
|
||||
@ -352,7 +354,7 @@ The above will not get appended to the existing search path.
|
||||
|
||||
For example, if `-Irel/` is used and `/usr/include/` is already on the search path, this does *not* mean that the file `/usr/include/rel/a.h`, can be included via `#include <a.h>`.
|
||||
|
||||
##View preprocessed file
|
||||
### View preprocessed file
|
||||
|
||||
This is mostly useful for learning purposes only.
|
||||
|
||||
@ -362,11 +364,11 @@ Using `cpp` directly:
|
||||
|
||||
Outputs the preprocessed file to stdout.
|
||||
|
||||
Using gcc as a frontend:
|
||||
Using `gcc` as a frontend:
|
||||
|
||||
gcc -E c.c
|
||||
|
||||
#Cross compile
|
||||
## Cross compile
|
||||
|
||||
Cross compiling means to compile a program for a different OS or architecture than the one the compiler is running.
|
||||
|
||||
@ -374,19 +376,19 @@ GCC cannot cross compile for windows from linux (TODO check).
|
||||
|
||||
This can be done with mingw (TODO how).
|
||||
|
||||
#Infamous error messages
|
||||
## Infamous error messages
|
||||
|
||||
Error messages that are difficult to interpret for noobs:
|
||||
|
||||
- `struct has incomplete type = struct undefined`. You forgot to include some header.
|
||||
|
||||
#Generated assembly
|
||||
## Generated assembly
|
||||
|
||||
This contains information that help to understand the assembly code generated by gcc, for example via the `-S` flag.
|
||||
|
||||
The generated assembly code is in the `gas` format. `gas` specific features shall not be explained here.
|
||||
|
||||
##Label name conventions
|
||||
### Label name conventions
|
||||
|
||||
- `.L*`: local labels to current file
|
||||
- `.LFB*`: function begin
|
||||
@ -396,7 +398,7 @@ The generated assembly code is in the `gas` format. `gas` specific features shal
|
||||
- `.LBB`:
|
||||
- `.LBE`:
|
||||
|
||||
#Sources
|
||||
## Sources
|
||||
|
||||
- <http://www.ibm.com/developerworks/library/l-gcc-hacks/>
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# glibc
|
||||
|
||||
glibc is GNU's implementation of:
|
||||
|
||||
- libc. By far the most popular implementation on Linux.
|
||||
|
@ -1,21 +1,25 @@
|
||||
# KDE
|
||||
|
||||
## Build and run
|
||||
|
||||
Build:
|
||||
|
||||
make
|
||||
|
||||
To run you have two choices:
|
||||
|
||||
- install and run from `PATH` (best option):
|
||||
- install and run from `PATH` (best option):
|
||||
|
||||
sudo make install
|
||||
kdecheat
|
||||
|
||||
- run directly from this directory:
|
||||
- run directly from this directory:
|
||||
|
||||
make run
|
||||
|
||||
The downside of this method is that it is necessary to install in order for certain features to apply, for example `ui.rc` files.
|
||||
|
||||
#KDE
|
||||
## General information
|
||||
|
||||
KDE is built on top of QT.
|
||||
|
||||
@ -32,7 +36,7 @@ A good way to learn APIs it to look for very simple applications, download the s
|
||||
|
||||
git clone git://anongit.kde.org/ksnakeduel
|
||||
|
||||
#ui.rc file
|
||||
## ui.rc file
|
||||
|
||||
Specifies GUI parts via an XML file.
|
||||
|
||||
|
@ -1,18 +1,24 @@
|
||||
# BLAS and LAPACK
|
||||
|
||||
TODO BROKEN: how to install LAPACKE on Ubuntu 12.04?
|
||||
|
||||
BLAS and LAPACK are:
|
||||
|
||||
- linear algebra packages
|
||||
- de-facto standards
|
||||
- non-parallel
|
||||
- originally written in Fortran
|
||||
- also have C interfaces available
|
||||
- linear algebra packages
|
||||
|
||||
- de-facto standards
|
||||
|
||||
- non-parallel
|
||||
|
||||
- originally written in Fortran
|
||||
|
||||
- also have C interfaces available
|
||||
|
||||
It might be a good idea to understand how to interface Fortran with C before the C interfaces.
|
||||
|
||||
#Related projects
|
||||
## Related projects
|
||||
|
||||
##BLAS
|
||||
### BLAS
|
||||
|
||||
<http://www.netlib.org/blas/>
|
||||
|
||||
@ -26,18 +32,18 @@ BLAS contains low level functions such as:
|
||||
|
||||
The BLAS project provides `cblas.h`, which contains a C interface for BLAS.
|
||||
|
||||
##LAPACK
|
||||
### LAPACK
|
||||
|
||||
LAPACK contains higher level functions such as:
|
||||
|
||||
- solving linear systems
|
||||
- eigenvalue/eigenvector calculations
|
||||
|
||||
It now includes an official C interface called `lapacke`.
|
||||
It now includes an official C interface called LAPACKE.
|
||||
|
||||
This does not ship with the Ubuntu `liblapack-dev` package at the time of writing, but there is a `liblapacke-dev` package available which provides it.
|
||||
|
||||
##ScaLAPACK
|
||||
### ScaLAPACK
|
||||
|
||||
<http://www.netlib.org/scalapack/>
|
||||
|
||||
@ -45,7 +51,7 @@ Continuation of LAPACK.
|
||||
|
||||
Considers parallelism.
|
||||
|
||||
##ATLAS
|
||||
### ATLAS
|
||||
|
||||
<http://math-atlas.sourceforge.net/>
|
||||
|
||||
@ -55,29 +61,29 @@ Implements full BLAS, but only part of LAPACK.
|
||||
|
||||
Has C interface.
|
||||
|
||||
#Installation on Ubuntu
|
||||
## Installation on Ubuntu
|
||||
|
||||
##Fortran
|
||||
### Fortran
|
||||
|
||||
sudo aptitude install liblapack-dev liblapack-doc libblas-doc
|
||||
|
||||
##C interface
|
||||
### C interface
|
||||
|
||||
via atlas:
|
||||
|
||||
sudo aptitude install
|
||||
|
||||
via lapacke (`libblas-dev` already contains `cblas.h`):
|
||||
via LAPACKE (`libblas-dev` already contains `cblas.h`):
|
||||
|
||||
sudo aptitude install liblapacke-dev
|
||||
|
||||
#Levels
|
||||
## Levels
|
||||
|
||||
1: array array. ex: array sum.
|
||||
2: matrix array. ex: solve linear system.
|
||||
3: matrix matrix. ex: multiply two matrices.
|
||||
|
||||
#Function naming conventions
|
||||
## Function naming conventions
|
||||
|
||||
The functions are named according to the pattern:
|
||||
|
||||
@ -85,25 +91,25 @@ The functions are named according to the pattern:
|
||||
|
||||
Where:
|
||||
|
||||
- `X`: data type:
|
||||
- `X`: data type:
|
||||
|
||||
- S: single precision (C float)
|
||||
- D: double precision
|
||||
- C: complex
|
||||
- Z: double complex
|
||||
|
||||
- `YY`: known type the type of input matrices:
|
||||
- `YY`: known type the type of input matrices:
|
||||
|
||||
- `GE`: general
|
||||
- `TR`: triangular
|
||||
|
||||
The more restrict the matrix type, the more efficient algorithms can be.
|
||||
|
||||
- `ZZ`: computation to be done:
|
||||
- `ZZ`: computation to be done:
|
||||
|
||||
- `SV`: SolVe linear system
|
||||
|
||||
#Sources
|
||||
## Sources
|
||||
|
||||
- function signatures: in source code olny <http://www.netlib.org/lapack/double/>
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
this dir demonstrates concepts which only make sense for multifile compilation such as:
|
||||
# Multi-file operations
|
||||
|
||||
This dir demonstrates concepts which only make sense for multi-file compilation such as:
|
||||
|
||||
- #include statements
|
||||
- static (.a) and dynamic (.so) creation/usage minimal example
|
||||
- ``static`` and ``extern`` keywords
|
||||
- two step ``.o`` -> exec makefile compilation
|
||||
- interlanguage compilation (c, cpp, fortran)
|
||||
- static (`.a`) and dynamic (`.so`) creation/usage minimal example
|
||||
- `static` and `extern` keywords
|
||||
- two step `.c` -> `.o` -> executable Makefile compilation
|
||||
- inter-language compilation: C, C++, Fortran
|
||||
|
@ -1 +1,3 @@
|
||||
# ODE
|
||||
|
||||
TODO BROKEN: how to install `drawstuff` on Ubuntu 12.04?
|
||||
|
@ -1,3 +1,5 @@
|
||||
# OpenCL
|
||||
|
||||
OpenCL is an open standard language which models CPU GPU computing.
|
||||
|
||||
It is similar to C, containing some extra keywords to model the CPU GPU world, and leaving out a few C features which GPUs cannot yet do very well.
|
||||
@ -8,7 +10,7 @@ The OpenCL standard in maintained by the Khronos Group, the same guys who mainta
|
||||
|
||||
OpenCL, like any other language has versions. As of 2013 the latest version is OpenCL 2.0 released in preview (unstable) as of Jul 2013.
|
||||
|
||||
#Install
|
||||
## Install
|
||||
|
||||
The first step is to get you GPU working. Good luck on that, specially if you are on Linux =)
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
#Test OpenCV is working
|
||||
# OpenCV
|
||||
|
||||
## Test OpenCV is working
|
||||
|
||||
If something goes wrong, you will want to first test that OpenCV is working properly.
|
||||
|
||||
@ -8,7 +10,7 @@ You can do that by running the example files
|
||||
cd examples/c
|
||||
./build-all.sh
|
||||
|
||||
#Usage
|
||||
## Usage
|
||||
|
||||
There are 2 versions of OpenCV.
|
||||
|
||||
@ -18,7 +20,7 @@ This is why you have both folders `/usr/include/opencv` and `/usr/include/opencv
|
||||
|
||||
For new projects, use OpenCV 2 only.
|
||||
|
||||
##Headers
|
||||
### Headers
|
||||
|
||||
The only header needed is `opencv2/opencv.hpp` which includes all the others.
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# OpenGL
|
||||
|
||||
This directory contains the main source of OpenGL cheats and information
|
||||
|
||||
OpenGL is an interface to use the graphics card for graphics.
|
||||
@ -6,7 +8,7 @@ It only contains basic primitives, and is often used together with other higher
|
||||
|
||||
OpenGL is only the interface, but there can be several implementations, open and closed source.
|
||||
|
||||
#Mesa
|
||||
## Mesa
|
||||
|
||||
Most common Linux OpenGL implementation. Open source.
|
||||
|
||||
@ -14,7 +16,7 @@ Used by X server.
|
||||
|
||||
Requirement of freeglut.
|
||||
|
||||
#GLUT
|
||||
## GLUT
|
||||
|
||||
GLUT is a higher level interface built on top of GL, and adds things like:
|
||||
|
||||
@ -26,9 +28,9 @@ GLUT is a higher level interface built on top of GL, and adds things like:
|
||||
|
||||
The original GLUT implementation is proprietary, but open source implementations exist such as Freeglut.
|
||||
|
||||
#Freeglut
|
||||
## Freeglut
|
||||
|
||||
Open source implementation of glut.
|
||||
Open source implementation of GLUT.
|
||||
|
||||
Often used together with the mesa implementation of GL.
|
||||
|
||||
@ -36,7 +38,7 @@ Installation Ubuntu on 12.04:
|
||||
|
||||
sudo aptitude install freeglut3-dev
|
||||
|
||||
#glxinfo
|
||||
## glxinfo
|
||||
|
||||
Good way to get information on OpenGL in Linux:
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Bouncing balls
|
||||
|
||||
Ball bouncing inside a box.
|
||||
|
||||
Simple sphere vs plane and sphere vs spheres collision detection.
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Texture FPS
|
||||
|
||||
Very simple example of textures and FPS collision detection.
|
||||
|
||||
Controls:
|
||||
@ -7,6 +9,4 @@ Controls:
|
||||
- `E`: fast
|
||||
- `X`: slow
|
||||
|
||||
# Sample run video
|
||||
|
||||
<http://youtu.be/wAQxIla7F68>
|
||||
Demo video: <http://youtu.be/wAQxIla7F68>
|
||||
|
@ -1,15 +1,5 @@
|
||||
linux/windows plotting library, with many language bindings.
|
||||
# PLplot
|
||||
|
||||
plotting outputs types are called *devices*,
|
||||
and can either be some window on the screen
|
||||
or files. New ones can be added as plugins
|
||||
Linux / Windows plotting library, with many language bindings.
|
||||
|
||||
#ubuntu install
|
||||
|
||||
main:
|
||||
|
||||
sudo aptitude install libplplot-dev
|
||||
|
||||
x-win device for plotting on screen instead of to a file:
|
||||
|
||||
sudo aptitude install plplot11-driver-xwin
|
||||
Plotting outputs types are called *devices*, and can either be some window on the screen or files. New ones can be added as plugins.
|
||||
|
@ -1 +1 @@
|
||||
POSIX C API.
|
||||
# POSIX C API
|
||||
|
@ -1,92 +1,94 @@
|
||||
# POSIX sockets
|
||||
|
||||
Sockets are similar to pipes but:
|
||||
|
||||
- allow communication across different systems and are thus a base for networks local sockets also exist.
|
||||
|
||||
- allow bidirection communication
|
||||
- allow bidirectional communication
|
||||
|
||||
- allow multiple clients to connet to a single server (the concepts of client and server are clearly defined)
|
||||
- allow multiple clients to connect to a single server (the concepts of client and server are clearly defined)
|
||||
|
||||
#What posix sockets can do
|
||||
## What POSIX sockets can do
|
||||
|
||||
POSIX sockets allows to implement any Application layer program, and thus to implement things like web browsers, crawlers or wget like utilities.
|
||||
POSIX sockets allows to implement any Application layer program, and thus to implement things like web browsers, crawlers or `wget` like utilities.
|
||||
|
||||
It seems however that POSIX does not support lower level layer control, for exapmle making an ICMP echo <http://www.microhowto.info/howto/send_an_arbitrary_ipv4_datagram_using_a_raw_socket_in_c.html>
|
||||
|
||||
For those functionalities it seems that Linux specific functionalities must be used for example raw sockets: <http://www.pdbuchan.com/rawsock/rawsock.html>
|
||||
|
||||
#Socket params
|
||||
## Socket params
|
||||
|
||||
sockets are characterized by three parameters:
|
||||
Sockets are characterized by three parameters:
|
||||
|
||||
- domain
|
||||
- type
|
||||
- protocol
|
||||
|
||||
this are exactly the 3 parameters that the `socket` call receives.
|
||||
This are exactly the 3 parameters that the `socket` call receives.
|
||||
|
||||
##Domain
|
||||
### Domain
|
||||
|
||||
- `AF_UNIX`: local sockets for single machine usage
|
||||
- `AF_UNIX`: local sockets for single machine usage.
|
||||
|
||||
UNIX domain sockets are uniquelly identified on the filesystem like pipes or other special files
|
||||
UNIX domain sockets are uniquely identified on the filesystem like pipes or other special files.
|
||||
|
||||
- `AF_INET`: internet IP protocol, regular local networks or the internet
|
||||
- `AF_INET`: internet IP protocol, regular local networks or the internet.
|
||||
|
||||
this is one of the few stream like resources that are not put into the filesystem because TODO
|
||||
This is one of the few stream like resources that are not put into the filesystem because TODO
|
||||
|
||||
- `AF_INET6`: IPv6
|
||||
|
||||
##Type
|
||||
### Type
|
||||
|
||||
- `SOCK_STREAM`: connexion works like a file stream to the program
|
||||
- `SOCK_STREAM`: connexion works like a file stream to the program.
|
||||
|
||||
in `AF_INET` this is automatically done via TCP/IP
|
||||
In `AF_INET` this is automatically done via TCP/IP.
|
||||
|
||||
delivery and ordering is guaranteed by TCP/IP
|
||||
Delivery and ordering is guaranteed by TCP/IP.
|
||||
|
||||
a connection is maintained while data is being sent
|
||||
A connection is maintained while data is being sent.
|
||||
|
||||
- `SOCK_DGRAM`: datagram
|
||||
- `SOCK_DGRAM`: datagram.
|
||||
|
||||
lower level protocol
|
||||
Lower level protocol.
|
||||
|
||||
does not establish connection
|
||||
Does not establish connection.
|
||||
|
||||
no automatic delivery guarantee
|
||||
No automatic delivery guarantee.
|
||||
|
||||
data must be manually split into packages of a maximum width
|
||||
Data must be manually split into packages of a maximum width.
|
||||
|
||||
in `AF_INET` this is UDP
|
||||
In `AF_INET` this is UDP.
|
||||
|
||||
certain domains may have differnt types
|
||||
Certain domains may have different types:
|
||||
|
||||
`AF_UNIX` has a single type: `SOCK_STREAM`
|
||||
- `AF_UNIX` has a single type: `SOCK_STREAM`.
|
||||
|
||||
`AF_INET` has the following types:
|
||||
- `AF_INET` has the following types: TODO
|
||||
|
||||
##Protocol
|
||||
### Protocol
|
||||
|
||||
sometimes it is possible to choose different protocols for a given type
|
||||
Sometimes it is possible to choose different protocols for a given type:
|
||||
|
||||
`0` uses the default protocol
|
||||
- `0` uses the default protocol
|
||||
|
||||
#Testing
|
||||
## Testing
|
||||
|
||||
- run the server:
|
||||
- Run the server:
|
||||
|
||||
./server &
|
||||
|
||||
- run as many clients as you want:
|
||||
- Run as many clients as you want:
|
||||
|
||||
./client && ./client
|
||||
./client
|
||||
|
||||
- kill the server:
|
||||
- Kill the server:
|
||||
|
||||
fg
|
||||
|
||||
and then hit Ctrl-C
|
||||
|
||||
#Local socket
|
||||
## Local socket
|
||||
|
||||
Is inserted into the filesystem.
|
||||
|
@ -1,6 +1,7 @@
|
||||
inet sockets, can be used across different computers for networking
|
||||
# Inet sockets
|
||||
|
||||
will only comment on differences from the unix sockets
|
||||
Inet sockets, can be used across different computers for networking.
|
||||
|
||||
once a connection has been made to a port, the port stays blocked,
|
||||
so be sure to take a port that is not being used
|
||||
Will only comment on differences from the UNIX sockets.
|
||||
|
||||
Once a connection has been made to a port, the port stays blocked, so be sure to take a port that is not being used.
|
||||
|
@ -1 +1,3 @@
|
||||
unix sockets, meant to be used locally on a single computer
|
||||
# UNIX sockets
|
||||
|
||||
UNIX sockets, meant to be used locally on a single computer
|
||||
|
10
qt/README.md
10
qt/README.md
@ -1,3 +1,5 @@
|
||||
# QT
|
||||
|
||||
Initial `qt.pro` template generated with:
|
||||
|
||||
qmake -project
|
||||
@ -27,16 +29,16 @@ QT adds new keywords to the C++ language such as `slots` and `emmit`. Those are
|
||||
|
||||
Some objects cannot be created on the stack, only on the heap. QT takes charge of their deletion when the time comes.
|
||||
|
||||
#Sources
|
||||
## Sources
|
||||
|
||||
- <www.zetcode.com/gui/qt4/firstprograms/>
|
||||
- <www.zetcode.com/gui/qt4/firstprograms/>
|
||||
|
||||
Short but good tutorial.
|
||||
|
||||
- <http://doc.qt.digia.com/4.7/all-examples.html>
|
||||
- <http://doc.qt.digia.com/4.7/all-examples.html>
|
||||
|
||||
The example list.
|
||||
|
||||
- on Ubuntu, get the source code for many examples:
|
||||
- On Ubuntu, get the source code for many examples:
|
||||
|
||||
sudo aptitude install -y qt4-demos
|
||||
|
Loading…
x
Reference in New Issue
Block a user