Skip to content

Commit 8b67c07

Browse files
committed
test a bunch of stuff from ./test
1 parent c2c3cd7 commit 8b67c07

Some content is hidden

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

41 files changed

+233
-340
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ C, C++, POSIX and Linux system programming minimal examples. Asserts used wherev
3737
1. [perf](perf.md)
3838
1. GCC
3939
1. [GCC -std= default](gcc-std-default/)
40-
1. [GNU LD linker](linker/)
40+
1. GNU LD linker
41+
1. [Incremental linking](linker/incremental-link/)
42+
1. [Fixed variable address](linker/variable-address/)
4143
1. Parsing
4244
1. [Flex and Bison](flex-bison/)
4345
1. Media

boost/common.hpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
#ifndef COMMON_HPP
2-
#define COMMON_HPP
3-
4-
#include <algorithm>
5-
#include <cassert>
6-
#include <iterator>
7-
#include <set>
8-
#include <unordered_map>
9-
#include <unordered_set>
10-
#include <utility> // pair
11-
#include <vector>
1+
#include "../cpp/common.hpp"
122

133
#include <boost/geometry.hpp>
144
#include <boost/iterator.hpp>
155

166
namespace bg = boost::geometry;
177
namespace bgi = bg::index;
18-
19-
#endif

boost/configure

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
2-
sudo aptitude update
3-
sudo aptitude install libboost1.48-all-dev
2+
sudo apt-get update
3+
sudo apt-get install libboost-all-dev

boost/rtree.cpp

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
/*
2-
Contains either:
3-
4-
- Point, Box or Segment, or something adapted to them
5-
- std::pair<Point, Data>
6-
- std::tuple<Point, ..., ...>
7-
8-
Documented at: http://www.boost.org/doc/libs/1_62_0/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.html
9-
10-
TODO
11-
12-
- randomized perf test vs linear search.
13-
14-
- ellipses, infinite lines, other parametrized surfaces:
15-
http://boost-geometry.203548.n3.nabble.com/intersection-between-a-sphere-and-a-line-td4025167.html
16-
*/
1+
// Contains either:
2+
//
3+
// - Point, Box or Segment, or something adapted to them
4+
// - std::pair<Point, Data>
5+
// - std::tuple<Point, ..., ...>
6+
//
7+
// Documented at: http://www.boost.org/doc/libs/1_62_0/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.html
8+
//
9+
// TODO
10+
//
11+
// - randomized perf test vs linear search.
12+
//
13+
// - ellipses, infinite lines, other parametrized surfaces:
14+
// http://boost-geometry.203548.n3.nabble.com/intersection-between-a-sphere-and-a-line-td4025167.html
1715

1816
#include "common.hpp"
1917

@@ -281,7 +279,6 @@ int main() {
281279

282280
// update
283281
// TODO: any hint insertion iterator as in std::set? Seems not.
284-
285282
{
286283
Rtree rtree;
287284
rtree.insert(Value(Point(1, 1), 1));

c/README.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1. Language
1616
1. [main function](main_function.c)
1717
1. [Command line arguments](interactive/command_line_arguments.c)
18-
1. [Ugly grammar](ugly_grammar.c)
18+
1. [Ugly grammar](interactive/ugly_grammar.c)
1919
1. Data
2020
1. [Identifier](identifier.c)
2121
1. [Uninitialized variable](uninitialized_variable.c)
@@ -24,19 +24,19 @@
2424
1. [Incomplete types](incomplete_type.c)
2525
1. [void](void.c)
2626
1. [Array](array.c)
27-
1. [Array designated initializer](array_designated_initializer.c)
28-
1. [String](string.c)
29-
1. [VLA](vla.c)
27+
1. [Array designated initializer](array_designated_initializer.c)
28+
1. [String](string.c)
29+
1. [VLA](vla.c)
3030
1. [Type qualifier](type_qualifier.c)
31-
1. [const](const.c)
32-
1. [restrict](restrict.c)
33-
1. [auto](auto.c)
34-
1. [register](register.c)
35-
1. [volatile](volatile.c)
31+
1. [const](const.c)
32+
1. [restrict](restrict.c)
33+
1. [auto](auto.c)
34+
1. [register](register.c)
35+
1. [volatile](volatile.c)
3636
1. User defined types
3737
1. [enum](enum.c)
3838
1. [typedef](typedef.c)
39-
1. [typedef function](typedef function.c)
39+
1. [typedef function](typedef function.c)
4040
1. [struct](struct.c)
4141
1. [struct operators](struct_operators.c)
4242
1. [struct designated initializer](struct_designated_initializer.c)
@@ -50,11 +50,11 @@
5050
1. Compile time operations
5151
1. [_Generic](generic.c)
5252
1. [Constant expression](constant_expression.c)
53-
1. [Static_assert](static_assert.c)
53+
1. [Static_assert](static_assert.c)
5454
1. [Pointer](pointer.c)
55-
1. [void pointer](void_pointer.c)
56-
1. [Pointer to int typecast](pointer_to_int.c)
57-
1. [NULL](null.c)
55+
1. [void pointer](void_pointer.c)
56+
1. [Pointer to int typecast](pointer_to_int.c)
57+
1. [NULL](null.c)
5858
1. Branching
5959
1. [if](if.c)
6060
1. [while](while.c)
@@ -96,13 +96,13 @@
9696
1. [stdint.h](stdint_h.c)
9797
1. [stdlib.h](stdlib_h.c)
9898
1. Exit related
99-
1. [exit()](exit.c)
100-
1. [atexit()](atexit.c)
101-
1. [abort()](interactive/abort.c.off)
102-
1. [abs()](abs.c)
103-
1. [malloc()](malloc.c)
104-
1. [getenv](getenv.c)
105-
1. [offsetof()](offsetof.c)
99+
1. [exit()](exit.c)
100+
1. [atexit()](atexit.c)
101+
1. [abort()](interactive/abort.c.off)
102+
1. [abs()](abs.c)
103+
1. [malloc()](malloc.c)
104+
1. [getenv](getenv.c)
105+
1. [offsetof()](offsetof.c)
106106
1. [string.h](string_h.c)
107107
1. [ctype.h](ctype_h.c)
108108
1. [time.h](time_h.c)
@@ -120,8 +120,8 @@
120120
1. [setjmp.h](setjmp_h.c)
121121
1. Applications
122122
1. [Design patterns](design_patterns.c)
123-
1. [Polymorphism](polymorphism.c)
124-
1. [C++ templates](template_cpp.c)
123+
1. [Polymorphism](polymorphism.c)
124+
1. [C++ templates](template_cpp.c)
125125
1. [String to int](string_to_int.c)
126126
1. [User input](interactive/user_input.c.off)
127127
1. [Memory layout](memory_layout.c)

c/common.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <time.h> /* time() */
2323
#include <wchar.h>
2424
#if __STDC_VERSION__ >= 199901L
25-
/* Not yet implemented in GCC 5.2. */
2625
# ifndef __STDC_NO_COMPLEX__
2726
# include <complex.h>
2827
# endif

c/interactive/abort.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
/*
2-
# abort
3-
4-
Raise a SIGABRT, an ANSI C signal which by default kills the program.
5-
6-
man abort
7-
8-
Sources:
9-
10-
- http://stackoverflow.com/questions/397075/what-is-the-difference-between-exit-and-abort
11-
- http://stackoverflow.com/questions/3676221/when-abort-is-preferred-over-exit
12-
13-
Differences from exit: does not run regular program teardown:
14-
15-
- does not call `atexit` function.
16-
- does not call C++ destructors
17-
*/
1+
/* # abort
2+
*
3+
* Raise a SIGABRT, an ANSI C signal which by default kills the program.
4+
*
5+
* man abort
6+
*
7+
* Bibliography:
8+
*
9+
* - http://stackoverflow.com/questions/397075/what-is-the-difference-between-exit-and-abort
10+
* - http://stackoverflow.com/questions/3676221/when-abort-is-preferred-over-exit
11+
*
12+
* Differences from exit: does not run regular program teardown:
13+
*
14+
* - does not call `atexit` function.
15+
* - does not call C++ destructors
16+
*/
1817

1918
#include "common.h"
2019

c/interactive/clock.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/*
2-
# clock
3-
*/
1+
/* # clock */
42

53
#include "common.h"
64

@@ -9,12 +7,11 @@ int main(void) {
97
uintmax_t i, j;
108

119
t = clock();
12-
/*
13-
Busy waiting.
14-
15-
Do something whacky, and then a printf side-effect,
16-
so that GCC won't be able to optimize it away.
17-
*/
10+
/* Busy waiting.
11+
*
12+
* Do something whacky, and then a printf side-effect,
13+
* so that GCC won't be able to optimize it away.
14+
*/
1815
j = (uintmax_t)time(NULL);
1916
for (i = 0; i < (uintmax_t)(CLOCKS_PER_SEC * 1000); i++) {
2017
j += i*i*i - i-j + 1;

c/posix/Makefile

-1
This file was deleted.

c/posix/README.md

-3
This file was deleted.

c/posix/atomic.c

-78
This file was deleted.

c/static/function/main.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
#include <stdio.h>
1+
#include <assert.h>
2+
#include <stdlib.h>
23

3-
void a();
4-
5-
/* OK: only declared, not defined. Will use the one in main. */
6-
void f() { puts("main i"); }
4+
/* OK: only declared, not defined. Will use the one in notmain. */
5+
int notmain_add(void);
76

87
/* OK: only visible to this file. */
9-
static void sf() { puts("main si"); }
8+
static int static_func(void) {
9+
return 0x10;
10+
}
11+
12+
int main_func(void) {
13+
return 0x1;
14+
}
1015

11-
void m() {
12-
f();
13-
sf();
16+
int main_add(void) {
17+
return main_func() + static_func();
1418
}
1519

1620
int main(void) {
17-
m();
18-
a();
19-
return 0;
21+
assert(main_add() == 0x011);
22+
assert(notmain_add() == 0x101);
23+
return EXIT_SUCCESS;
2024
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#include <stdio.h>
22

33
/* Link time error: already defined in main. */
4-
/*int i() { puts("si"); }*/
4+
/*int main_func() { puts("si"); }*/
55

66
/* OK: only declared, not defined. Will use the one in main. */
7-
void f(void);
7+
int main_func(void);
88

99
/* OK: only visible to this file. */
10-
static void sf() { puts("a si"); }
10+
static int static_func(void) {
11+
return 0x100;
12+
}
1113

12-
void a() {
13-
f();
14-
sf();
14+
int notmain_add(void) {
15+
return static_func() + main_func();
1516
}

0 commit comments

Comments
 (0)