C
main difference: C++ has classes and objects
| C++ | C |
|---|---|
| Classes and objects | storage, variables, data structures |
| Encapsulation | variable |
| inheritance | |
| polymorphism | _Generic |
| overloading | |
| namespaces | separated files, each c own 'static' names |
| exception handling | |
| memory(heap) allocation | |
| I/O (cin, cout) |
// pointer to a function
int (*v)(float f, char c)
// ^ pointer v that points to a function that accept float f and char c and return int
return _Generic(E,
float: 1,
long: 2,
default: -1)
// if E's type is float, return 1, long :2
#define absv(x) _Generic(x,
float: x < 0 ? -x : x;
double: x < 0 ? -x : x;
default: (x == INT_MIN? abort() : x < 0 ? -(x) : x);
POSIX: assume we have access to OS
C: programming standard can run without OS, support atomic access
(below are layers, from high to low)
gcc, clang, icc, nvcc, and some others that are tuned for architectures