Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
el_pollo_diablo
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
6 ms
·
31.
▲
by
el_pollo_diablo
1y ago
If, by "situation", you mean the development of a small program with so many constraints that using existing libraries is out if the question, then yes. Otherwise, that seems unwise to me. Not every user of a generic type has to b
32.
▲
by
el_pollo_diablo
1y ago
Sure, but your alternative code incorrectly assigns to (list)->payload. You have many other options. Without typeof, you can if(0) the assignment, or check type compatibility with a ternary operator like 1 ? (item) : (list)->payload a
33.
▲
by
el_pollo_diablo
1y ago
This is about a function definition, not a random function declarator. C23 does not change anything in that case.
34.
▲
by
el_pollo_diablo
1y ago
C23 does not change anything in this situation, because we are talking about the definition of main(), not a forward declaration. More details here: https://news.ycombinator.com/item?id=38729278#38732366
35.
▲
by
el_pollo_diablo
1y ago
Sure, that sort of language-specific idiosyncrasy must be dealt with in the compiler's front-end. In TFA's C example, consider that their loop while (i <= x) { // ... } just needs a slight transformatio
36.
▲
by
el_pollo_diablo
1y ago
> In fact, even state-of-art compilers will break language specifications (Clang assumes that all loops without side effects will terminate). I don't doubt that compilers occasionally break language specs, but in that case Clang is
37.
▲
by
el_pollo_diablo
2y ago
> seL4 is the only microkernel that has a proof of correctness ProvenCore ( https://provenrun.com/provencore/ ) has a proof that covers correctness (memory safety, and more generally absence of UB, termination, etc.),
38.
▲
by
el_pollo_diablo
2y ago
My comment was meant as a joke, given the context. I am familiar with these interjections, even as a non-native anglophone. Sorry for the time you took to write a good reply.
39.
▲
by
el_pollo_diablo
2y ago
> boy And nouns as interjections.
40.
▲
by
el_pollo_diablo
2y ago
Look, it's not that difficult: static inline uint32_t load_le32(void const *p) { unsigned char const *p_ = p; _Static_assert(sizeof(uint32_t) == 4, "uint32_t is not 4 bytes long"); return (uint32_t)p_[
41.
▲
by
el_pollo_diablo
2y ago
Another way to see it is to prepend every mathematical text involving ℤ with "for every ℤ such that [essential properties omitted]", so that you can apply it to several definitions of ℤ, rather than awkwardly redefining it after t
42.
▲
by
el_pollo_diablo
2y ago
What does source code/proof maintenance have to do with what remains at runtime? Sure, you can always extract the computational part of a program by erasing the logical parts, but that does not imply that code intermixed with logical p
43.
▲
by
el_pollo_diablo
2y ago
Disclaimer: my shop develops non-trivial low-level software with machine-checked correctness proofs. Rice's theorem implies that automatic static analysis (like Rust's borrow checker) will only get you that far. To go further, you
44.
▲
by
el_pollo_diablo
3y ago
I first learnt about Henry Darger in Olivia Laing's The Lonely City . It is a first-hand account of the psychological effects of loneliness and isolation. The author draws parallels between her own experience and that of other artists
45.
▲
by
el_pollo_diablo
3y ago
There is this snippet of code in the article: if buffer.len.saturating_sub(buffer.write.load()) >= write_len { // not shown: check `read` to make sure there's enough free room buffer.watermark.store(buffer.writ
46.
▲
by
el_pollo_diablo
3y ago
There are many problems with this concurrent queue. Here are a few I found in a cursory reading. In order to enqueue an element, you have to change two atomic pointers: tail->next and tail. That cannot be done atomically. enqueue() ass
47.
▲
by
el_pollo_diablo
3y ago
Not exactly. As of C17, the function definition you wrote implies that the function has no arguments, just like in C++. However, a declaration that is not part of a definition, like void fun(); (which you typically find in a head
48.
▲
by
el_pollo_diablo
3y ago
Yes, that's item 2 of the checklist in the original article.
49.
▲
by
el_pollo_diablo
3y ago
> max_align_t is only the max for scalar types, typically 8 or 16 bytes. But often math-intensive code wants 16 or 32 byte alignment for float arrays, to enable SIMD operations. Indeed, but _Alignof(max_align_t) is a good compromise for
50.
▲
by
el_pollo_diablo
3y ago
> The context parameter already addresses that need. How so? The context parameter identifies the allocator instance. What if the library needs to allocate objects with different alignment requirements with the same allocator instance? A
51.
▲
by
el_pollo_diablo
3y ago
> I don't have data on this but I feel that posix_memalign might be more widely supported than aligned_alloc. Possibly. IIRC Microsoft's CRT does not support aligned_alloc() because their implementation of free() cannot deal wi
52.
▲
by
el_pollo_diablo
3y ago
I don't think I have seen it in publicly available allocators either, but I once implemented it in a custom one. I suppose that this design is not very popular because it is quite fragile: you end up running arbitrary code (the move co
53.
▲
by
el_pollo_diablo
3y ago
C11 has aligned_alloc, which is more standard than posix_memalign, but there is no standard "aligned_realloc". There is no default alignment if all the functions of the allocator take it as a parameter, but it is reasonable for an
54.
▲
by
el_pollo_diablo
3y ago
If the library reallocates non-trivial objects, it may need a more sophisticated reallocation function, that does not simply bitwise copy a block to its new location. Some additional work may be needed (e.g. pointer fixup). The reallocation
55.
▲
by
el_pollo_diablo
3y ago
Unless all objects allocated by the library have one of the fundamental alignment requirements, I'd add a fourth item to the checklist: 4. All functions take the alignment requirement as a parameter. The alignment requirement must
56.
▲
by
el_pollo_diablo
3y ago
My personal favorite is by Hugo Kant: https://www.youtube.com/watch?v=wsWrU9h9WGI
57.
▲
by
el_pollo_diablo
3y ago
Furthermore, one advantage of this solution over using memcpy is that the compiler can still understand what it does (and aggressively optimize it) in a freestanding environment.
58.
▲
by
el_pollo_diablo
3y ago
Here is another solution for loading a potentially unaligned 64-bit integer in the CPU's byte order, that does not violate strict aliasing: uint64_t load64(uint8_t const *b) { union { uint64_t u64; uint8_t