Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
uecker
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
6 ms
·
91.
▲
by
uecker
2mo ago
Fair. If you only have one object to access such as the target pointer, then it probably makes not much difference with void-pointer based APIs such as qsort_r (for new APIs it would add type safety). Where it removes more boilerplate code
92.
▲
by
uecker
2mo ago
I agree with your point. But I usually prefer the later anyway, because the code usually is not as nested anyway and having a name is often helpful, and also because I find the nested code with lambdas also not too readable. Other languages
93.
▲
by
uecker
2mo ago
Or without qsort_r, you could use a thread local variable: typedef typeof(dsq) dsq_f; _Thread_local static wide(dsq_f) wdsq; wdsq = CLOSURE(dsq_f, dsq); https://godbolt.org/z/3e157c6b1
94.
▲
by
uecker
2mo ago
This is a good example. Without trampolines, this could look like this (Godbolt: https://godbolt.org/z/nK5fqMxjs ). int main() { struct Point { int x, y; } points[3] = { { 3
95.
▲
by
uecker
2mo ago
C++ has the same solution as I propose here: A wide function pointer type. In C++ it is called std::function, but this comes with a bit of baggage. C++ 26 has std::function_ref which would be the exact equivalent to my wide pointer. https:
96.
▲
by
uecker
2mo ago
I agree if your language is designed like this from the beginning as functional languages are, but in C you already have different syntax for functions. (edit: rephrased)
97.
▲
by
uecker
2mo ago
Correct (although the nightmare part is a bit exaggerated since return-oriented programming showed that non-executable stack does not help a lot). GCC can also put the trampoline on the heap, but this also has downsides. For me the main do
98.
▲
by
uecker
2mo ago
Lambdas are just anonymous nested functions. But I like named nested functions more because they are more readable and would prefer them in most cases. Ideally you have both as most languages have. I always wondered why C++ only added lambd
99.
▲
by
uecker
2mo ago
My old patch from 2018? This was not accepted to GCC because it relied on function pointers being aligned and there were concerns with this. But I prefer this approach anyhow, as it does not impose any run-time cost for checking the tag, an
100.
▲
by
uecker
2mo ago
I don't understand this comment. There are well-defined ABIs for many platforms. Sometimes there is a defacto ABI defined by the first compiler supporting this platform, but generally there ABI groups that agree on a common ABI for eac
101.
▲
by
uecker
2mo ago
You are right that there are cases where it is not possible. But it also works when arguments are not passed in registers. The condition then is that there are less stack slots used than in the caller. https://godbolt.org/z&
102.
▲
Using GCC's Nested Functions with Wide Pointers and No Trampolines II
(uecker.codeberg.page)
103 points
by
uecker
2mo ago
|
47 comments
103.
▲
by
uecker
2mo ago
That version would at least warn with -Wall.
104.
▲
by
uecker
2mo ago
What specific examples do you have in mind where you would get a useful warning with a C++ compiler that you can not also get for C with gcc?
105.
▲
by
uecker
2mo ago
GCC warns by default since version 5, released more than a decade ago.
106.
▲
by
uecker
2mo ago
Yes, g++ -xc will call the regular C FE. So yes, do not try to compile C code using a C++ compiler. That you somehow get superior type checking with C++ is not really true anymore, as essentially all important parts were integrated into the
107.
▲
by
uecker
2mo ago
Renewables is more economical than nuclear, so investing in nuclear is a waste of resources. This is also why nobody does it. And no, nobody who hasn't lost their marbles is seriously considering sending people to Mars to save humanity
108.
▲
by
uecker
2mo ago
We haven't reached peak coal because we did not start developing renewables earlier. We did waste a huge amount of resources in nuclear in the past, which still never became cheap enough. That we now see a transition away from fossil f
109.
▲
by
uecker
2mo ago
No, because nuclear energy is not a cost effective measure against climate change. Solar is.
110.
▲
by
uecker
2mo ago
Backdoored developers are ok?
111.
▲
by
uecker
2mo ago
I do not blindly trust anything, and come to the conclusion that downloading binaries from Debian trixie is a lot more safe. There is a world of difference between "curl | sh" and downloading from a curated package repository main
112.
▲
by
uecker
2mo ago
Yes, it does not solve the problems described there.
113.
▲
by
uecker
2mo ago
It is also relevant for dynamic linking on all Linux binary distributions.
114.
▲
by
uecker
2mo ago
Indeed, it now admits this. But what problem is this then really solving?
115.
▲
by
uecker
2mo ago
Huh, compiler interoperability is extremely useful. It usually works by ABI groups defining a common ABI for each architecture and compilers then following these ABIs (although not required a compilers that does not is poor)
116.
▲
by
uecker
2mo ago
Yes, using an arbitrary type that is different from the one of the object is UB. But any access of a representation byte using a character pointer is well defined, not just memcpy and I would also not call memcpy useless.
117.
▲
by
uecker
2mo ago
Yes, Rust copied many good ideas from C (and added many new). BTW: If you use character-pointers, you also do not need to worry about strict-aliasing in C.
118.
▲
by
uecker
2mo ago
Maybe provide a concrete example instead of making vague accusations. Or rather, please not, it is not a useful discourse. A productive response to my comment would be an insightful explanation of how byte-level access to memory objects is
119.
▲
by
uecker
2mo ago
This is certainly not true. Accessing bytes of objects is well-defined in C.
120.
▲
by
uecker
2mo ago
The issue is that a programmer is allowed to declare a function on its own without including the header, but then a function aliasing feature would not be visible and does not help. But if we waived this allowance, then a simple macro woul
More ›