@@ -12,7 +12,7 @@ This article focuses on some of the non-obvious and easy to make mistakes
1212non-experienced C programmers are likely to make and are/can not completely
1313be covered by tooling without going into edge cases relevant to performance
1414and covering the most simple and conservative approach:
15- - 1.[Pointer semantics](# pointer_semantics)
15+ - 1.[Pointer semantics]($link.unsafeRef(' pointer_semantics') )
1616- 2.[Sequence points](#seq_pts)
1717- 3.[Bit-fields](#bitfields)
1818
@@ -57,17 +57,17 @@ abbreviated via macro `NULL`.
5757[]($section.id("pointer_access_practice"))
5858**Pointer access** in **practice**.
5959- Provenance as regions pointer is allowed to point to for access.
60- [provenance.c]($code.asset('./ provenance.c').language('c'))
60+ [provenance.c]($code.asset('provenance.c').language('c'))
6161- Copy around some bytes from not overlapping regions (otherwise use memmove).
62- [copy_bytes.c]($code.asset('./ copy_bytes.c').language('c'))
62+ [copy_bytes.c]($code.asset('copy_bytes.c').language('c'))
6363- Correct alignment of pointers with temporary, when necessary.
64- [correct_alignment.c]($code.asset('./ correct_alignment.c').language('c'))
64+ [correct_alignment.c]($code.asset('correct_alignment.c').language('c'))
6565- Ensure correct storage and padding size for pointers via sizeof.
66- [storage_padding.c]($code.asset('./ storage_padding.c').language('c'))
66+ [storage_padding.c]($code.asset('storage_padding.c').language('c'))
6767- Allowed aliasing of pointers (type-based aliasing analysis)
68- [allowed_aliasing.c]($code.asset('./ allowed_aliasing.c').language('c'))
68+ [allowed_aliasing.c]($code.asset('allowed_aliasing.c').language('c'))
6969- Non-allowed aliasing of pointers (type-based aliasing analysis)
70- [non_allowed_aliasing.c]($code.asset('./ non_allowed_aliasing.c').language('c'))
70+ [non_allowed_aliasing.c]($code.asset('non_allowed_aliasing.c').language('c'))
7171
7272[]($section.id("pointer_exceptions"))
7373**The Exceptions**
@@ -81,7 +81,7 @@ abbreviated via macro `NULL`.
8181 back. This also means that `sizeof (function pointer) == sizeof (void *)` must be uphold, which is not true for
8282 microcontrollers with separate address space for code and data or CHERI in mixed capability mode/hybrid compilation mode.
8383 Address space annotations are mandatory for this to work and it is unfortunate that standards do not reflect this as of 2024-04-28.
84- [aliasing_exceptions_uniform_address_space.c]($code.asset('./ aliasing_exceptions_uniform_address_space.c').language('c'))
84+ [aliasing_exceptions_uniform_address_space.c]($code.asset('aliasing_exceptions_uniform_address_space.c').language('c'))
8585
8686[]($section.id("pointer_construction_requirements"))
8787**Pointer construction requirements** are unspecified in all C standards with potentially some hints and nothing
@@ -154,12 +154,12 @@ Other more elaborative examples can be seen in the github gist "What is the Stri
154154
155155[]($section.id("opaque"))
156156Opaque type idiom.
157- [opaque.h]($code.asset('./ opaque.h').language('c'))
158- [opaque.c]($code.asset('./ opaque.c').language('c'))
157+ [opaque.h]($code.asset('opaque.h').language('c'))
158+ [opaque.c]($code.asset('opaque.c').language('c'))
159159
160160[]($section.id("ptrintconv"))
161161Pointer to integer and integer to pointer conversion.
162- [ptrtoint_inttoptr.c]($code.asset('./ ptrtoint_inttoptr.c').language('c'))
162+ [ptrtoint_inttoptr.c]($code.asset('ptrtoint_inttoptr.c').language('c'))
163163
164164[]($section.id("lto"))
165165Link time optimization (LTO) usage and problems. One can use `ptrtoint_inttoptr.c` with flags for strong LTO
@@ -172,24 +172,24 @@ compiler automatically do runtime selection of the best SIMD routine instead of
172172is vectorized and one has to check for example via `clang -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize`
173173or `gcc -O3 -ftree-vectorizer-verbose=3` and use [clang extensions](https://clang.llvm.org/docs/LanguageExtensions.html)
174174and [gcc extensions](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) like `__builtin_assume_aligned`.
175- [extern_avx.h]($code.asset('./ extern_avx.h').language('c'))
176- [extern_avx.c]($code.asset('./ extern_avx.c').language('c'))
177- [memcpy_avx.c]($code.asset('./ memcpy_avx.c').language('c'))
175+ [extern_avx.h]($code.asset('extern_avx.h').language('c'))
176+ [extern_avx.c]($code.asset('extern_avx.c').language('c'))
177+ [memcpy_avx.c]($code.asset('memcpy_avx.c').language('c'))
178178
179179[]($section.id("cerberus"))
180180Checking C code validity with Cerberus does not imply absence of compiler miscompilations.
181- [cerberus_install.sh]($code.asset('./ cerberus_install.sh').language('bash'))
182- [extern_miscompilation.h]($code.asset('./ extern_miscompilation.h').language('c'))
183- [extern_miscompilation.c]($code.asset('./ extern_miscompilation.c').language('c'))
184- [ptr_provenance_miscompilation.c]($code.asset('./ ptr_provenance_miscompilation.c').language('c'))
181+ [cerberus_install.sh]($code.asset('cerberus_install.sh').language('bash'))
182+ [extern_miscompilation.h]($code.asset('extern_miscompilation.h').language('c'))
183+ [extern_miscompilation.c]($code.asset('extern_miscompilation.c').language('c'))
184+ [ptr_provenance_miscompilation.c]($code.asset('ptr_provenance_miscompilation.c').language('c'))
185185
186186[]($section.id("cheri"))
187187CHERI usage is left as task for the reader. Useful links are `https://github.com/CTSRD-CHERI/cheribuild`,
188188`https://github.com/CTSRD-CHERI/cheri-c-programming` and `https://github.com/capablevms/cheri-examples`.
189189
190190[]($section.id("seq_pts"))
191191**Sequence Points** in simple case and with storage lifetime extension.
192- [sequence_points.c]($code.asset('./ sequence_points.c').language('c'))
192+ [sequence_points.c]($code.asset('sequence_points.c').language('c'))
193193
194194[]($section.id("bitfields"))
195195**Bit-fields** should not be used unless for non-portable code regarding
0 commit comments