Skip to content

Commit bc46513

Browse files
committed
Split most of C++
1 parent d9f60f8 commit bc46513

61 files changed

Lines changed: 7545 additions & 7239 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile_many‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
# by the Makefile default values.
99
MYCC ?= gcc
1010
MYCXX ?= g++
11-
DEFINES ?= #-D_XOPEN_SOURCE 700
12-
INCLUDE_DIRS ?= #-I/usr/include
11+
D ?= #-D_XOPEN_SOURCE 700
12+
I ?= #-I/usr/include
1313
O ?= 0
1414
STD ?= c11
1515
PEDANTIC ?= -pedantic-errors
16-
CFLAGS ?= $(DEFINES) -O$(O) -std=$(STD) -Wextra $(PEDANTIC) $(CFLAGS_EXTRA)
17-
MYCXXFLAGS ?= $(DEFINES) -O$(O) -std=c++11 -Wextra $(PEDANTIC) $(CXXFLAGS_EXTRA)
16+
CFLAGS ?= $(D) -O$(O) -std=$(STD) -Wextra $(PEDANTIC) $(CFLAGS_EXTRA)
17+
MYCXXFLAGS ?= $(D) -O$(O) -std=c++11 -Wextra $(PEDANTIC) $(CXXFLAGS_EXTRA)
1818

1919
LIBS ?= -lm #-lGL -lGLU -lglut
2020

@@ -65,10 +65,10 @@ ifneq ($(strip $(run)),)
6565
endif
6666

6767
$(OUT_DIR)%$(OUT_EXT): $(IN_DIR)%.c
68-
$(MYCC) $(CFLAGS) $(PROFILE_DEFINE) $(PROFILE_FLAGS) $(DEBUG_DEFINE) $(DEBUG_FLAGS) $(INCLUDE_DIRS) -o "$@" "$<" $(LIBS)
68+
$(MYCC) $(CFLAGS) $(PROFILE_DEFINE) $(PROFILE_FLAGS) $(DEBUG_DEFINE) $(DEBUG_FLAGS) $(I) -o "$@" "$<" $(LIBS)
6969

7070
$(OUT_DIR)%$(OUT_EXT): $(IN_DIR)%.cpp
71-
$(MYCXX) $(MYCXXFLAGS) $(PROFILE_DEFINE) $(PROFILE_FLAGS) $(DEBUG_DEFINE) $(DEBUG_FLAGS) $(INCLUDE_DIRS) -o "$@" "$<" $(LIBS)
71+
$(MYCXX) $(MYCXXFLAGS) $(PROFILE_DEFINE) $(PROFILE_FLAGS) $(DEBUG_DEFINE) $(DEBUG_FLAGS) $(I) -o "$@" "$<" $(LIBS)
7272

7373
$(OUT_DIR)%$(OUT_EXT): $(IN_DIR)%.f
7474
$(FF) $(FFLAGS) $(PROFILE_DEFINE) $(PROFILE_FLAGS) $(DEBUG_DEFINE) $(DEBUG_FLAGS) -o "$@" "$<" $(FFLIBS)

‎c/common.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <signal.h>
1212
#include <stdbool.h> /* false, true */
1313
#include <stdarg.h> /* ..., va_list, va_start, va_arg, va_end */
14-
#include <stddef.h> /* offsetof, type_t */
14+
#include <stddef.h> /* offsetof, size_t, type_t */
1515
#include <stdlib.h> /* malloc, EXIT_SUCCESS, EXIT_FAILURE: */
1616
#include <stdio.h> /* printf, puts */
1717
#include <string.h> /* sprintf, strlen, strcpy, memset, memcmp */

‎c/float_h.c‎

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "common.h"
1414

1515
int main() {
16-
puts("float.h");
17-
1816
/*
1917
# Rounding method
2018
@@ -33,21 +31,7 @@ int main() {
3331
TODO can it be changed?
3432
*/
3533
{
36-
printf(" FLT_ROUNDS = %d\n", FLT_ROUNDS);
37-
}
38-
39-
/*
40-
# FLT_EVAL_METHOD
41-
42-
Precision to which floating point operations are evaluated
43-
44-
it seems that floating operations on, say, floats can be evaluated
45-
as long doubles always.
46-
47-
TODO understand better
48-
*/
49-
{
50-
printf(" FLT_EVAL_METHOD = %d\n", FLT_EVAL_METHOD);
34+
printf("FLT_ROUNDS = %d\n", FLT_ROUNDS);
5135
}
5236

5337
/*
@@ -59,9 +43,9 @@ int main() {
5943
and support is optional.
6044
*/
6145
{
62-
printf(" FLT_MIN = %a\n", FLT_MIN);
63-
printf(" DBL_MIN = %a\n", DBL_MIN);
64-
printf(" LDBL_MIN = %La\n", LDBL_MIN);
46+
printf("FLT_MIN = %a\n", FLT_MIN);
47+
printf("DBL_MIN = %a\n", DBL_MIN);
48+
printf("LDBL_MIN = %La\n", LDBL_MIN);
6549
}
6650

6751
/*
@@ -78,7 +62,7 @@ int main() {
7862
TODO wow, there are non radix 2 representation implementations?!
7963
*/
8064
{
81-
printf(" FLT_RADIX = %d\n", FLT_RADIX);
65+
printf("FLT_RADIX = %d\n", FLT_RADIX);
8266
}
8367

8468
#if __STDC_VERSION__ >= 201112L
@@ -124,9 +108,9 @@ int main() {
124108
- 1: yes
125109
*/
126110
{
127-
printf(" FLT_HAS_SUBNORM = %d\n", FLT_HAS_SUBNORM);
128-
printf(" DBL_HAS_SUBNORM = %d\n", DBL_HAS_SUBNORM);
129-
printf(" LDBL_HAS_SUBNORM = %d\n", LDBL_HAS_SUBNORM);
111+
printf("FLT_HAS_SUBNORM = %d\n", FLT_HAS_SUBNORM);
112+
printf("DBL_HAS_SUBNORM = %d\n", DBL_HAS_SUBNORM);
113+
printf("LDBL_HAS_SUBNORM = %d\n", LDBL_HAS_SUBNORM);
130114

131115
assert(isnormal(LDBL_MIN));
132116

‎c/function.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ int main() {
242242
allocated data on caller and pass a pointer to the struct,
243243
and let the callee modify that pointer to return it.
244244
245-
Smaple: definition
245+
Sample: definition
246246
247247
struct struct_func_struct struct_func() {
248248
struct struct_func_struct s = { 0, 1 };

‎c/math_h.c‎

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -399,62 +399,15 @@ int main() {
399399

400400
/* float in given range. */
401401
{
402-
float min = 1.0;
403-
float max = 3.0;
402+
float min = 1.0f;
403+
float max = 3.0f;
404404
float res = (max - min) * ((float)rand() / RAND_MAX) + min;
405405
printf("float in range = %f\n", res);
406406
}
407407
}
408408

409409
/*
410-
# IEEE-754
411-
412-
IEC 60559 has the same contents as the IEEE 754-2008,
413-
Outside of the C standard it is commonly known by the IEEE name, or simply as IEEE floating point.
414-
415-
IEEE dates from 1985.
416-
417-
# __STDC_IEC_559__
418-
419-
# IEC 60599
420-
421-
Standard on which floating point formats and operations should be available
422-
on an implementation, and how they should work.
423-
424-
Good overview wiki article: <http://en.wikipedia.org/wiki/IEEE_floating_point>
425-
426-
Many CUPs implement large parts of IEC 60599, which C implementations can use if available.
427-
428-
The C standard specifies that implementing the IEC 60599 is not mandatory.
429-
430-
If the macro `__STDC_IEC_559__` is defined this means that the implementation is compliant
431-
to the interface specified in Annex F of the C11 standard.
432-
433-
C99 introduced many features which allow greater conformance to IEC 60599.
434-
*/
435-
{
436-
#ifdef __STDC_IEC_559__
437-
puts("__STDC_IEC_559__");
438-
439-
/*
440-
C float is 32 bits, double 64 bits.
441-
442-
long double extende precision, and could be one of the format not spceified by IEC.
443-
444-
IEC explicitly allows for extended formats, and makes basic restrictions such that
445-
its exponent should have more bits than the preceding type.
446-
447-
This is probably the case to accomodate x86's 80 bit representation.
448-
*/
449-
{
450-
assert(sizeof(float) == 4);
451-
assert(sizeof(double) == 8);
452-
}
453-
#endif
454-
}
455-
456-
/*
457-
# division by 0
410+
# Division by 0
458411
459412
Time to have some fun and do naughty things.
460413
@@ -607,5 +560,16 @@ int main() {
607560
}
608561
}
609562

563+
/*
564+
# FLT_EVAL_METHOD
565+
566+
# float_t
567+
568+
# double_t
569+
*/
570+
{
571+
printf("FLT_EVAL_METHOD = %d\n", FLT_EVAL_METHOD);
572+
}
573+
610574
return EXIT_SUCCESS;
611575
}

‎c/preprocessor.c‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ assert(false);
362362
*/
363363

364364
/*
365-
# Prefined preprocessor macros
365+
# Predefined preprocessor macros
366366
367367
# Standard preprocessor defines
368368
@@ -526,6 +526,48 @@ assert(false);
526526
puts("___X32_SYSCALL_BIT");
527527
#endif
528528

529+
/*
530+
# IEEE-754
531+
532+
IEC 60559 has the same contents as the IEEE 754-2008,
533+
Outside of the C standard it is commonly known by the IEEE name, or simply as IEEE floating point.
534+
535+
IEEE dates from 1985.
536+
537+
# __STDC_IEC_559__
538+
539+
# IEC 60599
540+
541+
Standard on which floating point formats and operations should be available
542+
on an implementation, and how they should work.
543+
544+
Good overview wiki article: <http://en.wikipedia.org/wiki/IEEE_floating_point>
545+
546+
Many CUPs implement large parts of IEC 60599, which C implementations can use if available.
547+
548+
The C standard specifies that implementing the IEC 60599 is not mandatory.
549+
550+
If the macro `__STDC_IEC_559__` is defined this means that the implementation is compliant
551+
to the interface specified in Annex F of the C11 standard.
552+
553+
C99 introduced many features which allow greater conformance to IEC 60599.
554+
*/
555+
{
556+
#ifdef __STDC_IEC_559__
557+
puts("__STDC_IEC_559__");
558+
559+
/*
560+
I think it guaranteed by the standard on annex F:
561+
562+
- The float type matches the IEC 60559 single format.
563+
- The double type matches the IEC 60559 double format.
564+
- The long double type matches an IEC 60559 extended format,307) else a
565+
non-IEC 60559 extended format, else the IEC 60559 double format.
566+
*/
567+
assert(sizeof(float) == 4);
568+
assert(sizeof(double) == 8);
569+
#endif
570+
}
529571
}
530572

531573
return EXIT_SUCCESS;

‎c/register.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
# register
33
4+
Storage class specifier.
5+
46
Hint to compiler that ri be stored in register
57
instead of in RAM.
68
@@ -11,6 +13,12 @@
1113

1214
#include "common.h"
1315

16+
/* Can appear in arguments. */
17+
void f(register int i) {}
18+
19+
/* -pedantic: File scope declaration. */
20+
/*register int i;*/
21+
1422
int main() {
1523
{
1624
register int ri;

‎c/restrict.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
No behaviour change, but allows for further compiler optimization,
1414
so it should be used whenever possible. See generated assembly to spot the difference.
1515
16-
Great example showing how restrict could help optimize things: <http://en.wikipedia.org/wiki/Restrict>
16+
Great example showing how restrict could help optimize things: http://en.wikipedia.org/wiki/Restrict
1717
*/
1818

1919
#include "common.h"

‎c/standards.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Major new features:
6666

6767
- `gcc` flag: add `-std=c99`
6868

69-
WG14/N1256 is the best free draft available: <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>
69+
WG14/N1256 is the best free draft available: <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> Does not seem to exist in HTML: <http://stackoverflow.com/questions/4883212/html-version-of-c-standard-draft-n1256-pdf>
7070

7171
#### Microsoft C99 support
7272

‎cpp/README.md‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,36 @@
33
1. Introduction
44
1. [Style guides](style-guides.md)
55
1. [Standards](standards.md)
6-
1. [Standard library](standard_library.md)
76
1. [Trivia](trivia.md)
87
1. Language
9-
1. [main.cpp](main.cpp): huge dump of subjects being split up
8+
1. [main.cpp](main.cpp)
109
1. [Hello world](hello_world.cpp)
10+
1. [const](const.cpp)
11+
1. [constexpr](constexpr.cpp)
12+
1. [auto](auto.cpp)
13+
1. [decltype](decltype.cpp)
14+
1. [nullptr](nullptr.cpp)
15+
1. [reference](reference.cpp)
16+
1. [rvalue reference](rvalue_reference.cpp)
17+
1. [Function](function.cpp)
18+
1. [Operator overload](operator_overload.cpp)
19+
1. [Conversion function](conversion_function.cpp)
20+
1. [Lambda](lambda.cpp)
21+
1. [explicit](explicit.cpp)
22+
1. [class](class.cpp)
23+
1. [namespace](namespace.cpp)
24+
1. [template](template.cpp)
25+
1. [exception](exception.cpp)
26+
1. [typedef](typedef.cpp)
27+
1. [typecast](typecast.cpp)
28+
1. [new](new.cpp)
29+
1. [Preprocessor](preprocessor.cpp)
30+
1. [Standard library](standard_library.md)
31+
1. [Headers](common.hpp)
32+
1. [limits](limits.cpp)
33+
1. [thread](thread.cpp)
34+
1. [atomic](atomic.cpp)
35+
1. [mutex](mutex.cpp)
36+
1. [memory](memory.cpp)
37+
1. Applications
38+
1. [Design patterns](design_patterns.cpp)

0 commit comments

Comments
 (0)