-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysprog_needs_to_know.txt
108 lines (91 loc) · 3.52 KB
/
sysprog_needs_to_know.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
WHAT A SYSTEM PROGRAMMER NEEDS TO KNOW
(Notes for oneself and the addendum for THE C++ CODE REVIEWER NOTES https://github.com/kuzminrobin/first_step_on_github/blob/master/cpp_code_reviewer_notes.txt)
Contents.
=========
[VLA] Variable Length Array.
[VLA]
What a system programmer needs to know about
Variable Length Array.
=======================
Conclusion:
-----------
Variable Length Array is a C language feature (starting with C99) but not a C++ language feature (as of C++14).
What the Variable Length Array is.
----------------------------------
It is stack-allocated array whose length is a run-time value. E.g.
void func(char *pc)
{
char arr[strlen(pc)]; // The length of `arr` is a run-time value.
}
The Variable Length Arrays, since they are stack-allocated, are more efficient than the heap-allocated arrays.
Recommendations:
----------------
If you need to use the Variable Length Arrays in C++ code (and want the code to be portable and warningless) then consider placing the code (using the Variable Length Array) in the `.c` files and compiling using the C (not C++) compiler. E.g.
VLA_code.h
void func(char *pc); // Declaration in C header.
VLA_code.c
void func(char *pc) // Definition in C file.
{
char arr[strlen(pc)]; // The length of `arr` is a run-time value.
. . .
}
VLA_user.cpp
extern "C" { // Use C language linkage in C++ code.
#include "VLA_code.h"
}
. . .
func("Hello, World!"); // Call to C function from C++ code.
What the Variable Length Array is, Standard Citation:
-----------------------------------------------------
C99, 6.7.5.2 Array declarators, paragraph 4:
If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type; otherwise, the array type is a variable length array type.
Compiler warnings/errors (https://godbolt.org):
-----------------------------------------------
Comipler options: -Wextra -pedantic -std=c++03
[ARM gcc 4.6.4 (linux) #1] warning: ISO C++ forbids variable length array 'array' [-Wvla].
[x86-64 clang 5.0.0 #1] warning: variable length arrays are a C99 feature [-Wvla-extension].
No compiler options:
[x86 MSVC 19 2017 RTW #1] error C2131: expression did not evaluate to a constant
Standard Provisions:
--------------------
C99 (ISO/IEC 9899:1999 (E)): Search for "variable length array", "variable-length array", "VLA".
C?? (Latest, TODO).
C++03 (ISO/IEC 14882:2003(E)): ?
C++14/17 (TODO)
TODO:
=====
Terms
System Programming
Non-lang Specific
const
When to use asserts (see also Before Writing Asserts)
C++
Logging
Alexandrescu article.
Before Writing Singleton Design Pattern
Before Writing Smart Pointers
Before Writing Asserts
Type-Safe Programming
Jonathan Muller
Non-Ignorable Return Value
New Features in a Specific Edition of the C++ Standard
Anthony Calandra
Other Langs
Advantages of C over C++
[VLA]
Struct initializer (struct { char c; int i; } s = { .c = 2, .i = 1 };)
Advantages of D over C++
How Nested Functions Can Help To Avoid `goto`
Advantages of Rust over C++
How to Accelerate
GIT Cloning
Shallow Clones
Symlink to a local GIT repo (.git) - Single Full Repo, Multiple Working Dirs.
The Build
ccache
Building on a RAM Drive
SSD Drive
People
Where a Person Known in System Programming World Can Be Met
Walter Bright (the designer of the D programming language)
Chronological List of System Programming Books