News for hackers. Stuff that matters.
Re:I love coding in C by swiley on Thursday December 26, 2019 @09:35AM (#21884035)
I honestly don’t like C++ at all as a programmer, “C” is way better for hacking.

For example: I understand why the standard was written the way it was but syntactic closures in C++ are way worse than GNU C.

Re:I love coding in C by geofft on Thursday December 26, 2019 @10:27AM (#21884394)
Don't GNU C's closures/nested functions require an executable stack or something?

I remember GNU GRUB going through and getting rid of all of them.

Re:I love coding in C by a1369209993 on Thursday December 26, 2019 @03:02PM (#21886277)
The implementation uses a executable stack, but they could do it differently if they cared.

Eg, https://news.ycombinator.com/item?id=21635551 with alternating ro+x and rw-x pages holding thunks and fptr+data pairs.

Re:I love coding in C by saagarjha on Thursday December 26, 2019 @10:36AM (#21884479)
Yes, because that’s where they put trampolines that are generated on the fly. (They don’t need to do this, but that’s how it’s currently implemented.)
Re:I love coding in C by Gibbon1 on Thursday December 26, 2019 @03:37PM (#21886552)
I use them. The executable stack bit doesn't bother me since I'm on an ARM Cortex. Would be nice if they fixed that because they are kinda handy once you get used to them.
Re:I love coding in C by geofft on Thursday December 26, 2019 @07:08PM (#21887972)
> The executable stack bit doesn't bother me since I'm on an ARM Cortex.

I'm not familiar enough with ARM - what does ARM Cortex give you here?

Re:I love coding in C by Gibbon1 on Thursday December 26, 2019 @07:46PM (#21888160)
It's what it doesn't give me. Doesn't have a memory management unit, so no stack execution protection. So no protection against classic stack smashing attacks.

I saw a talk about weird machines. The upshot of it is if you can clobber the return address on the stack you can usually create a weird machine that you can then program[1]. Leads me to believe that if you are putting entrusted data and return addresses on the same stack you're in a state of sin security wise.

https://en.wikipedia.org/wiki/Weird_machine

[1] Also saw an exploit on an embedded system where they leveraged that even though the memory was locked you could set the program counter and read/write registers via jtag. Using that they were able in short order to recover the devices security keys and re-flash it with their own code.

Re:I love coding in C by saagarjha on Thursday December 26, 2019 @09:56AM (#21884197)
What are syntactic closures in GNU C?
Re:I love coding in C by swiley on Thursday December 26, 2019 @10:04AM (#21884247)
This [1] explains how to create them using nested functions. Near the end is a quick blurb about the implementation which is probably why c++ doesn’t do it that way.

[1] https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

Re:I love coding in C by saagarjha on Thursday December 26, 2019 @10:09AM (#21884287)
Oh no, nested functions are a terrible, insecure hack that are far too verbose to be ergonomic closures :(
Re:I love coding in C by swiley on Friday December 27, 2019 @08:36AM (#21891234)
Of course, that’s why I said it’s good for hacking.

Although I’m not sure I agree about the “ergonomic” thing.

Re:I love coding in C by amiga_500 on Thursday December 26, 2019 @10:11AM (#21884296)
Wouldn't you just use a lambda nowadays?
Re:I love coding in C by im3w1l on Thursday December 26, 2019 @10:30AM (#21884422)
Not in C you wouldn't.
Re:I love coding in C by saagarjha on Thursday December 26, 2019 @10:36AM (#21884481)
You can with Clang’s blocks extension: https://en.wikipedia.org/wiki/Blocks_(C_language_extension)
Re:I love coding in C by amiga_500 on Thursday December 26, 2019 @10:41AM (#21884526)
Sure, but the parent post was saying they didn't like nested function handling in c++.
Re:I love coding in C by im3w1l on Thursday December 26, 2019 @01:48PM (#21885790)
Nested functions don't exist in C++ (except for lambdas).
Re:I love coding in C by MiroF on Thursday December 26, 2019 @11:16AM (#21884777)
Agreed - this feature seems useless in modern C++
Re:I love coding in C by JustSomeNobody on Thursday December 26, 2019 @11:33AM (#21884910)
I don’t like C++ anymore. I used to love it but now it’s just a bloated mess of a language. I get it, you don’t have to use every part of the language but I really don’t like any of the newer bits and that’s what everyone wants to use.
Re:I love coding in C by adgasf on Thursday December 26, 2019 @11:48AM (#21885010)
I can't imagine writing C++ without lambdas and auto
Re:I love coding in C by ncmncm on Thursday December 26, 2019 @04:25PM (#21886923)
Yes, generic lambdas in 2014 made coding C++ fun. The range library in C++20 will do it again.