Skip to content

Commit de99282

Browse files
committed
socket file io
1 parent f31150c commit de99282

25 files changed

Lines changed: 639 additions & 173 deletions

‎c/typecast.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,14 @@ int main() {
268268
*/
269269
}
270270

271+
/*
272+
# Typecast between two struct types
273+
274+
- http://stackoverflow.com/questions/3766229/casting-one-struct-pointer-to-other-c
275+
- http://stackoverflow.com/questions/27127914/why-is-this-implicit-conversion-between-different-pointer-types-valid?lq=1
276+
- http://stackoverflow.com/questions/10998639/is-it-possible-to-cast-struct-to-another
277+
- http://stackoverflow.com/questions/8416417/nested-structs-and-strict-aliasing-in-c
278+
*/
279+
271280
return EXIT_SUCCESS;
272281
}

‎c/undefined-behaviour.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Examples:
1212
- negative shift `1 << -1`: <http://stackoverflow.com/questions/4945703/left-shifting-with-a-negative-shift-count>
1313
- access object after its lifetime: `int *ip = 0; {int i = 1; ip = &i;} *ip++;`
1414
- modify `const` variable with pointer cast that removes `const`
15+
- strict aliasing rule: <http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule>, this example is great <http://stackoverflow.com/a/16534243/895245> as it shows an optimization that can be legally done upon undefined behaviour
16+
17+
Lists of examples:
18+
19+
- <http://stackoverflow.com/questions/98340/what-are-the-common-undefined-unspecified-behavior-for-c-that-you-run-into>
1520

1621
### Why the spec ever use undefined behaviour instead of implementation defined behaviour?
1722

‎cpp/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
1. Language
88
1. [main.cpp](main.cpp)
99
1. [Hello world](hello_world.cpp)
10+
1. [goto crosses initialization of](goto-cross-initialization.cpp)
1011
1. [const](const.cpp)
1112
1. [RTTI](rtti.md)
1213
1. Compile time magic
@@ -32,6 +33,7 @@
3233
1. [Most vexing parse](most_vexing_parse.cpp)
3334
1. [Inheritance and constructors](inheritance_and_constructors.cpp)
3435
1. [Delegating constructor](delegating_constructor.cpp)
36+
1. [Implicitly deleted constructor](implicitly_deleted_constructor.cpp)
3537
1. [virtual](virtual.cpp)
3638
1. [Method pointer, operator .* and operator ->*](method_pointer.cpp)
3739
1. [Pure virtual](pure_virtual.cpp)
@@ -71,6 +73,8 @@
7173
1. [memory](memory.cpp)
7274
1. [regex](regex.cpp)
7375
1. [utility](utility.cpp)
76+
1. Smart pointers
77+
1. [unique_ptr](unique_ptr.cpp)
7478
1. Applications
7579
1. [Design patterns](design_patterns.cpp)
7680

‎cpp/class.cpp‎

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ int main() {
858858
- the most vexing parse only happens for default constructors.
859859
- the default constructor can be is implicitly declared and defiend by the compiler.
860860
861+
There are other functions which are also defined by default:
862+
https://en.wikipedia.org/wiki/Special_member_functions
863+
861864
# Implicily declared constructors
862865
863866
If no explicit constructor is declared,
@@ -1203,32 +1206,31 @@ int main() {
12031206
}
12041207

12051208
#if __cplusplus >= 201103L
1206-
12071209
/*
1208-
# brace enclosed initializer list
1210+
# Brace enclosed initializer list
12091211
12101212
See inializer list
12111213
1212-
# list initialization
1214+
# List initialization
12131215
12141216
See initializer list constructor.
12151217
1216-
# initializer list contructor
1218+
# Initializer list contructor
12171219
12181220
Useful in cases where you don't know beforehand how many arguments
12191221
a constructor should receive.
12201222
12211223
For example, the stdlib std::vector class gets an initializer list constructor on C++11,
12221224
which allows one to initialize it to any constant.
12231225
1224-
TODO0 could this not be achieved via cstdarg?
1226+
TODO could this not be achieved via cstdarg?
12251227
*/
12261228
{
12271229
//STL std::vector usage example
12281230
{
12291231
std::vector<int> v{0, 1};
1232+
// SAME.
12301233
//std::vector<int> v = std::vector<int>({0, 1});
1231-
//SAME
12321234
assert(v[0] == 0);
12331235
assert(v[1] == 1);
12341236
assert(v == std::vector<int>({0, 1}));
@@ -1681,55 +1683,6 @@ int main() {
16811683
//CopyAndSwap c2(c0);
16821684
}
16831685

1684-
#if __cplusplus >= 201103L
1685-
/*
1686-
# xvalue
1687-
1688-
# glvalue
1689-
1690-
# prvalue
1691-
1692-
In addition to the C99 rvalues and lvalues,
1693-
the C++11 standard defines new concepts:
1694-
1695-
- xvalue
1696-
- glvalue
1697-
- prvalue
1698-
1699-
<http://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues>
1700-
1701-
This is probably a consequence of move semantincs.
1702-
1703-
*/
1704-
1705-
/*
1706-
# move constructor
1707-
1708-
Constructor that takes rvalues instead of lvalues.
1709-
1710-
Used to implement move semantics.
1711-
1712-
# move semantics
1713-
1714-
Useful in situtations where a class manages dynamic data.
1715-
1716-
Basic idea: when copying from an rvalue, it is not necessary to make an expensive copy of it:
1717-
it suffices to acquire its data via swap, and leave it on a valid state (via a default constructor for example).
1718-
1719-
This is true because the rvalue passed to a copy constructor cannot be seen.
1720-
1721-
Value reference allows to overload the copy constructor based not on type,
1722-
but on the fact that a value is an rvalue or an lvalue!
1723-
1724-
No change must be done to the copy and swap idiom for move semantics to work for the assigment operator,
1725-
since in C++11 `int i = rvale` calls a move consttuctor on `i` while `int i = lvalue` calls a copy constructor.
1726-
1727-
<http://stackoverflow.com/questions/3106110/what-is-move-semantics>
1728-
*/
1729-
{
1730-
}
1731-
#endif
1732-
17331686
/*
17341687
# as-if rule
17351688

‎cpp/goto-cross-initialization.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Jump crosses initialization of ...
3+
http://stackoverflow.com/questions/5685471/error-jump-to-case-label
4+
5+
Same with switch cases.
6+
*/
7+
8+
#include "common.hpp"
9+
10+
int main() {
11+
goto after
12+
;
13+
// ERROR
14+
//int i = 0;
15+
after:
16+
;
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
# Implicitly deleted constructor
3+
4+
Some characteristics of classes delete default constructors
5+
that would otherwise be generated automatically.
6+
7+
http://en.cppreference.com/w/cpp/language/copy_assignment
8+
Deleted implicitly-declared copy assignment operator
9+
*/
10+
11+
#include "common.hpp"
12+
13+
int main() {
14+
// const non-class data member.
15+
{
16+
{
17+
//class C {
18+
// Warning GCC 5.2: non-static const member
19+
// in class without a constructor.
20+
//const int i;
21+
//};
22+
// ERROR use of deleted function C::C
23+
//C c;
24+
}
25+
{
26+
class C {
27+
int i;
28+
};
29+
C c;
30+
}
31+
}
32+
}

‎cpp/list.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "common.hpp"
1818

1919
int main() {
20-
//initializer list constructor
20+
// Initializer list constructor
2121
{
2222
std::list<int> l{0, 1};
2323
}

‎cpp/move.cpp‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
# move constructor
3+
4+
# move semantics
5+
6+
Useful in situations where a class heap allocated data.
7+
8+
Made possible by C++11 rvalue references.
9+
10+
Basic idea: when copying from an rvalue, it is not necessary to make an expensive copy of it:
11+
it suffices to acquire its data via swap, and leave it on a valid state (via a default constructor for example).
12+
13+
This is true because the rvalue passed to a copy constructor cannot be seen.
14+
15+
Value reference allows to overload the copy constructor based not on type,
16+
but on the fact that a value is an rvalue or an lvalue!
17+
18+
No change must be done to the copy and swap idiom for move semantics to work for the assigment operator,
19+
since in C++11 `int i = rvale` calls a move consttuctor on `i` while `int i = lvalue` calls a copy constructor.
20+
21+
# Sources
22+
23+
- http://stackoverflow.com/questions/3106110/what-is-move-semantics
24+
- http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html
25+
- http://stackoverflow.com/questions/3413470/what-is-stdmove-and-when-should-it-be-used
26+
27+
# xvalue
28+
29+
# glvalue
30+
31+
# prvalue
32+
33+
In addition to the C99 rlvalues and values,
34+
the C++11 standard defines new concepts:
35+
36+
- xvalue
37+
- glvalue
38+
- prvalue
39+
40+
http://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues
41+
42+
This is probably a consequence of move semantics.
43+
*/
44+
45+
#include "common.hpp"
46+
47+
int main() {
48+
#if __cplusplus >= 201103L
49+
// TODO example
50+
#endif
51+
}

0 commit comments

Comments
 (0)