Skip to content

Commit 8070970

Browse files
committed
test even more stuff
1 parent 8b67c07 commit 8070970

24 files changed

+83
-98
lines changed

README.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ C, C++, POSIX and Linux system programming minimal examples. Asserts used wherev
1515
1. [GCC](gcc/): GCC extensions
1616
1. [Shared library](shared-library/)
1717
1. Introduction
18-
1. [C vs C++](c-vs-cpp.md)
18+
1. [C vs C++](c-vs-cpp.md)
1919
1. Cross-language
2020
1. [C from C++](c-from-cpp/)
2121
1. [C++ from C](cpp-from-c/)
@@ -51,21 +51,22 @@ C, C++, POSIX and Linux system programming minimal examples. Asserts used wherev
5151
1. [glibc](glibc/)
5252
1. [Linux](linux/)
5353
1. GUI
54-
1. [GTK](gtk/)
55-
1. [KDE](kde/)
56-
1. [OpenGL](opengl/)
57-
1. [Qt](qt/)
58-
1. [SDL](sdl/)
59-
1. [X11](x11)
54+
1. [GTK](gtk/)
55+
1. [KDE](kde/)
56+
1. [OpenGL](opengl/)
57+
1. [Qt](qt/)
58+
1. [SDL](sdl/)
59+
1. [X11](x11/)
60+
1. [X11 hello world](x11/hello_world.c)
6061
1. Scientific
61-
1. [Bullet physics](bullet/)
62-
1. [CUDA](cuda/)
63-
1. [Fortran](fortran/)
64-
1. [GSL](gsl/)
65-
1. [LAPACK](lapack/)
66-
1. [OpenCL](opencl/)
67-
1. [OpenCV](opencv/)
68-
1. [PLplot](plplot/)
62+
1. [Bullet physics](bullet/)
63+
1. [CUDA](cuda/)
64+
1. [Fortran](fortran/)
65+
1. [GSL](gsl/)
66+
1. [LAPACK](lapack/)
67+
1. [OpenCL](opencl/)
68+
1. [OpenCV](opencv/)
69+
1. [PLplot](plplot/)
6970
1. [CONTRIBUTING](CONTRIBUTING.md)
7071
1. [TODO](TODO.md)
7172
1. [Bibliography](bibliography.md)

boost/Makefile_params

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
LIBS := -lm -lboost_graph -lboost_filesystem -lboost_system
1+
LIBS := -lm -lboost_graph -lboost_filesystem -lboost_system

c-from-cpp/Makefile

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
.POSIX:
2-
.PHONY: run clean
32

4-
main.out: main.o c.o
5-
g++ -o '$@' $^
3+
.PHONY: clean run test
64

7-
c.o: c.c
8-
gcc -c -g -o '$@' -std=c89 -Wall -Wextra -pedantic-errors '$<'
5+
main.out: main.o notmain.o
6+
g++ -o '$@' $^
97

108
main.o: main.cpp
119
g++ -c -g -o '$@' -std=c++98 -Wall -Wextra -pedantic-errors '$<'
1210

13-
run: main.out
14-
./main.out
11+
notmain.o: notmain.c
12+
gcc -c -g -o '$@' -std=c89 -Wall -Wextra -pedantic-errors '$<'
1513

1614
clean:
1715
rm -f *.o *.out
16+
17+
test: main.out
18+
./main.out

c-from-cpp/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# C from C++
2-
3-
<https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c/30526795#30526795>
1+
https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c/30526795#30526795

c-from-cpp/c.c

-3
This file was deleted.

c-from-cpp/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <cassert>
22

3-
#include "c.h"
3+
#include "notmain.h"
44

55
int main() {
6-
assert(f() == 1);
6+
assert(notmain_func() == 1);
77
}

c-from-cpp/notmain.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "notmain.h"
2+
3+
int notmain_func(void) { return 1; }

c-from-cpp/c.h renamed to c-from-cpp/notmain.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef C_H
2-
#define C_H
1+
#ifndef NOTMAIN_H
2+
#define NOTMAIN_H
33

44
/* This ifdef allows the header to be used from both C and C++. */
55
#ifdef __cplusplus
66
extern "C" {
77
#endif
8-
int f();
8+
int notmain_func(void);
99
#ifdef __cplusplus
1010
}
1111
#endif

cpp-from-c/Makefile

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
.POSIX:
2+
23
.PHONY: run clean
34

4-
main.out: main.o cpp.o
5+
main.out: main.o notmain.o
56
g++ -o '$@' $^
67

7-
cpp.o: cpp.cpp
8+
notmain.o: notmain.cpp
89
g++ -c -g -o '$@' -pedantic-errors -std=c++98 -Wall -Wextra '$<'
910

1011
main.o: main.c
1112
gcc -c -g -o '$@' -pedantic-errors -std=c89 -Wall -Wextra '$<'
1213

13-
run: main.out
14-
./main.out
15-
1614
clean:
1715
rm -f *.o *.out
16+
17+
test: main.out
18+
./main.out

cpp-from-c/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# C++ from C
2-
3-
<https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c/30526795#30526795>
1+
https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c/30526795#30526795

cpp-from-c/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <assert.h>
22

3-
#include "cpp.h"
3+
#include "notmain.hpp"
44

55
int main(void) {
66
assert(f_int(1) == 2);

cpp-from-c/cpp.cpp renamed to cpp-from-c/notmain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cpp.h"
1+
#include "notmain.hpp"
22

33
int f(int i) {
44
return i + 1;

cpp-from-c/cpp.h renamed to cpp-from-c/notmain.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CPP_H
2-
#define CPP_H
1+
#ifndef NOTMAIN_HPP
2+
#define NOTMAIN_HPP
33

44
#ifdef __cplusplus
55
// C cannot see these overloaded prototypes, or else it would get confused.

shared-library/basic/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
CC_DL = gcc -ggdb3 -std=c89 -Wall -Wextra
22
CC = $(CC_DL) -pedantic-errors
33

4-
.PHONY: all clean run
4+
.PHONY: all clean test
55

66
all: maina.out mainso.out mainso_fullpath.out dlopen.out
77

8-
run: all
8+
test: all
99
./maina.out
1010
LD_LIBRARY_PATH=. ./mainso.out
1111
./mainso_fullpath.out

shared-library/basic/dlopen.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* Used by: https://unix.stackexchange.com/questions/226524/what-system-call-is-used-to-load-libraries-in-linux/462710#462710 */
2+
13
#define _XOPEN_SOURCE 700
24
#include <assert.h>
35
#include <dlfcn.h>

shared-library/lib-lib-dependency/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
CC := gcc -pedantic-errors -std=c89 -Wall -Wextra
22

3-
.PHONY: all clean run
3+
.PHONY: all clean test
44

55
main.out: main.o libcirosantilli_a.so
66
$(CC) -L'.' main.o -o '$@' -lcirosantilli_a
77
@#LD_LIBRARY_PATH=. $(CC) -L'.' main.o -o '$@' -lcirosantilli_a
88

9-
run: main.out
9+
test: main.out
1010
LD_LIBRARY_PATH=. ./main.out
1111

1212
libcirosantilli_a.so: a.o libcirosantilli_b.so

shared-library/symbol-version/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
CC := gcc -pedantic-errors -std=c89 -Wall -Wextra
22

3-
.PHONY: all clean run
3+
.PHONY: all clean test
44

55
all: main.out main1.out main2.out
66

7-
run: all
7+
test: all
88
LD_LIBRARY_PATH=. ./main.out
99
LD_LIBRARY_PATH=. ./main1.out
1010
LD_LIBRARY_PATH=. ./main2.out
+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
# Symbol version
2-
3-
Trying to replicate glibc's `symbol@@VERSION` madness.
4-
5-
This allows you to have a single library `v2`, that also contains symbols from `v1`.
6-
7-
<https://stackoverflow.com/questions/8823267/linking-against-older-symbol-version-in-a-so-file/51856826#51856826>
1+
https://stackoverflow.com/questions/8823267/linking-against-older-symbol-version-in-a-so-file/51856826#51856826

shared-library/symbol-version/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "a.h"
55

66
/* TODO: any clearer way of doing this maybe
7-
* with some compilation option only? */
7+
* with some compilation option only?
8+
*/
89
#if defined(V1)
910
__asm__(".symver a,a@LIBA_1");
1011
#elif defined(V2)

test

+5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ top="$(pwd)"
77
# make test
88
for t in \
99
c \
10+
c-from-cpp \
1011
c/extern \
1112
c/static/function \
1213
c/static/variable \
1314
cpp \
15+
cpp-from-c \
1416
cpp/extern_const \
1517
cpp/inline_variable \
1618
gcc \
1719
glibc \
1820
linker/incremental-link \
1921
linker/variable-address \
2022
posix \
23+
shared-library/basic \
24+
shared-library/lib-lib-dependency \
25+
shared-library/symbol-version \
2126
; do
2227
if ! make -C "$t" -j`nproc` test; then
2328
echo "TEST FAILED: $t"

x11/Makefile

-19
This file was deleted.

x11/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile_many

x11/Makefile_params

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBS := -lX11

x11/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# X11
22

33
1. [Hello world](hello_world.c)
4-
1. [Bibliography](bibliography.md)
54

65
Major graphical system on Linux systems.
76

x11/hello_world.c

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
/*
2-
x11 c interface hello world
3-
4-
Expected outcome: shows a window with white background
5-
and a black X drawn on it.
6-
7-
Exit when either:
8-
9-
- the X close button of the window is clicked
10-
- a mouse on the window is released
11-
*/
1+
/* x11 c interface hello world
2+
*
3+
* Expected outcome: shows a window with white background
4+
* and a black X drawn on it.
5+
*
6+
* Exit when either:
7+
*
8+
* - the X close button of the window is clicked
9+
* - a mouse on the window is released
10+
*/
1211

1312
#include <stdlib.h>
1413

1514
#include "X11/Xlib.h"
1615

1716
int main(void) {
1817
Display *dsp = XOpenDisplay(NULL);
19-
if (!dsp){ return EXIT_FAILURE; }
18+
if (!dsp) {
19+
return EXIT_FAILURE;
20+
}
2021
int screenNumber = DefaultScreen(dsp);
2122
unsigned long white = WhitePixel(dsp, screenNumber);
2223
unsigned long black = BlackPixel(dsp, screenNumber);
2324
Window win = XCreateSimpleWindow(
24-
dsp,
25-
DefaultRootWindow(dsp),
26-
50, 50,
27-
200, 200,
28-
0, black,
29-
white);
25+
dsp,
26+
DefaultRootWindow(dsp),
27+
50, 50,
28+
200, 200,
29+
0, black,
30+
white
31+
);
3032
XMapWindow(dsp, win);
3133
long eventMask = StructureNotifyMask;
3234
XSelectInput(dsp, win, eventMask);

0 commit comments

Comments
 (0)