Live data from Hacker News

*(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

youtube.com

151–160 of 199 posts

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#151

Not a big fan of the format of the talk. The guy is a good orator, but it takes ages to go to the point. A bit annoying if you're actually interested in the technical part rather than the jokes.

Yup, I’m not going to burn 54 minutes of my life listening to something that should take 30 seconds to convey.

Your comment misses the point of the talk. It isn't to explain to the viewer what that line of code does, it's to talk about talking about what that line of code does.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#152
post #85

Earlier quoted context omitted.

Back in the day there were no protections. You could write to any address whether it was used by the CPU for interrupt vectors, part of the OS, hardware addresses, anything.

Sure, but I'm asking if that's something that's enabled by default today or not. I don't see why it's unreasonable for things that were useful "back in the day" to not be available with the default arguments on current versions of compilers but available with certain flags. I'm not sure why my question touched a nerve, because I'm genuinely asking both if I understand correctly and if it's something that needs a flag…

In older CPUs there was no memory management hardware and no virtual memory. You could just read/write in code from any address anywhere and you'd be writing to that actual physical memory in the computer. This wasn't a feature so much as it is a lack of a feature.

Modern CPUs with virtual memory means the question is a lot more complicated. Every process in a modern OS gets it's own address space so you can write to 0 but it could go anywhere (even virtualized to disk) and all the actual hardware is not directly accessible (must go through the OS).

I'm not sure I'd call this ability "useful" except if you're writing an operating system. This is vast simplification but when your computer boots it's effectively in a mode that allows reading/writing to anywhere. The OS kernel has direct access to all the hardware and then it limits access when running user processes.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#153

Earlier quoted context omitted.

I ask it to quote the section and it helps to find. But if you prefer reading the transcript that’s fine too. It’s not a commandment. It’s my sharing what works for me.

Fair enough. I was not criticising you, sorry if it sounded that way. I am just puzzled by instances where it seems an old fashioned approach (such as control-F in this case) would perform at least as well as fancy (and not always reliable) AI techniques.

The transcript is AI-generated sadly, so it isn't typo-free enough for Cmd-F always. Especially programming content gets messed up. "char" -> "car" and so on and so forth, but GPT-4 will correctly fix all that up.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#154
For the typical non-coder hacker news reader:

Wait for C++ coder to get disney sponsorship for a stack frame version of/translation to George Lucas expressions / Steven Speilburg expressions.

aka * wars vs. * trek crossover comparisons, perhaps with less () than lisp/scheme take.

Ideally, in UTF format so no "7 samuri/8 bit kleen", AND/OR, lower API, protocol droids distractions.

In interm, learn python, show a python version of beetles 'let it be' and 'eigen a feeling'[1] parody.

Although, perhaps 'irq feeling' more on topic with an appropriate reference to irq hooks & NULL dumps.

Perhaps get DMCA'd by Wierd Al for using wrong character color scheme.

".plan 0[]", long[sigh] different discussion?

http://www.asciimation.co.nz/

[0] : sigh[long] : http://news.ycombinator.com/item?id=3367392

[1] : http://news.ycombinator.com/item?id=34261699

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#155
post #122

Earlier quoted context omitted.

> that value does not have to be address 0, it could be some other address. That's what the spec says, but are there any computers around anymore where nullptr is not zero? The spec should really go with the times IMHO, old hardware can be supported via platform-specific language extensions.

The cleanest way would probably be to get rid of 0 as a null pointer constant, make its use in contexts that expect a pointer illegal and replace it with an explicit keyword. Of course that would break all existing code that uses 0 or (void*)0 instead of NULL, but if you are out to break things anyway you might as well get rid of 40 year old warts.

Ah a new standard! Perfect! Everyone will adopt this as clearly it is better and there’s no reason not to right? … right?

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#156
post #143

Earlier quoted context omitted.

Not at all, that is a guarantee that people actually know how to hold the scapel and can enter the operating room safely. A brick layer doesn't turn into a Construction Engineer, only because they think they know everything about building houses, and have somehow built their own during long weekends. Likewise a coder out of a bootcamp, isn't someone versed in what actually entails to be a Software Engineer, regarless…

No, it’s not a guarantee, it’s just a noisy filter with a very high false negative rate and a high enough false positive rate (as visible in malpractice insurance).

I certainly is, those numbers would be much higher without that filter.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#157
post #88

Crash? For example test code that makes your app crash, in order to test... say if your crashdumps work as expected?

I've done it, on purpose, to cause a crash, so that it would drop a core file and I could find out exactly how it got to that point in the code. (g++ on an ARM, on an embedded system running embedded Linux, with lots of functions that could be called by more than one thread. "ulimit -c unlimited".)

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#159
post #103
post #63

Earlier quoted context omitted.

I think an even more accurate analogy would be if a surgeon had some kind of scalpel with a 1 cm limit, but if a surgery suddenly changes in the middle, and suddenly requires a deeper incision, the surgeon has to spend a non-zero amount of time re-configuring the scalpel. This casts flexibility vs safety as a tradeoff, which it is.

Oh, one more refinement: Surgeons are constantly killing people[1], and every time, it turns out it was because the surgeon disabled a known, recommended safety rail, and whenever anyone points out that they should stop disabling the safety rails, they insist that they know how to operate without them, it's those other people that don't. Plus it's sooooo inconvenient for an operation[2] to take five more minutes, the…

The one thing I remember from watching my wife's surgery is that they counted the surgical sponges going in, and counted them coming back out. Because sometimes surgeons would forget and leave a sponge inside and then the person woudl get a really bad infection.

Honestly, checklists and procedure matter more than most people want to admit.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#160
post #118
post #25

When I see that code my head immediately translates to "store a byte with value 0 at memory address zero". 0 the integer needs to be cast to a char * to treat it as a byte address (rather than a word) and the * means "assign to the memory location given by the pointer. I would probably use something like this when hacking on an Apple II with a zero page. I have also written programs that ran on VMS which dumped memor…

You're mostly correct but to be pedantic, in C the literal value 0 does not actually mean address 0. The literal value of 0 is an implementation defined value that represents a null pointer, but that value does not have to be address 0, it could be some other address. This is significant because the following two snippets of code are not required to be equal in C. char* c = (char*)(0); char* d; memset(&d, 0, sizeof(d…

Perhaps a hascii take on the bending spoon in the matrix scene would be better *char reference.
Post reply on HN