Commenters share experiences with magic numbers and debugging
3 Sep 21 9:34 PM · 2d ago · 2 comments · 1 source · development 3 of 3
Reddit commenters begin discussing the technical details of magic numbers and null pointer protection on early systems like the Macintosh, with nostalgia for debugging challenges on older architectures.
“Could someone explain what "sticking number into location 0" means, and how does it crash the program?”
rhoki-bg, Reddit commenter · reddit ↗connorboyle Lobsters userbirdculture Hacker News user
The whole story postscomments the bright band is this development · numbered dots are the others · click one to jump
What people said 18 voices · verbatim
-
This post is mostly just speculation. If you want the actual answer for why CAFEBABE was chosen, james gosling himself actually [gave an answer](https://radio-weblogs.com/0100490/2003/01/28.html) > As far as I know, I'm the guilty party on this one. I was totally unaware of the NeXT connection. The small number of interesting HEX words is probably…
-
At the time it was created, there were parts of the internet that would only send 7 bits per bite for some data transfers, so any magic number with the high bit set was a quick way to test if your file has been corrupted. PNG made that choice public, don’t recall what Gosling was thinking though.
-
> Subject: Re: Why CAFEBABE? > > Date: Wed May 22 09:17:37 1996 > > Since the word babe is pretty synonmous with chick, I doubt you'll find any _deep_ meaning here. When I hear "CafeBabe" I think of a typical Coffee Grrl: nose peirced, minimum one tatoo, hair dyed black, hate the world the government and parents, and is rather attractive in a…
-
On the Macintosh, which lacks protected memory, a popular thing to do is to stick some magic number into location 0 so that dereferencing a null pointer or handle will crash immediately. Could someone explain what "sticking number into location 0" means, and how does it crash the program?
-
> Twenty-something years ago the Burroughs B6700 initialized its "uninitialized" memory of 48-bit words to `0xBADBADBADBAD` OT1H, very cool; OTOH, 48 bit words :-D I presume that's related to BCD being 6bit
-
I’m having flashbacks to programming the 68000 chip in college DEADBEEF was better than writing to 0000000 but still tear hair out when debugging and see that in a variable. Writing to zero just rebooted and my sanity was gone waiting for the reboot and rebuild from the network
-
While we're sharing our favourite 32-bit values, I'm aware of a few indie/hobby projects using `0xACAB1312` as their magic number.
-
Old World Macs didn't have a kernel. System code was by and large in a ROM. All code ran at system level, and some Mac functionality could only be effected by manipulating low memory.
-
This is interesting, and a little shocking that CAFE wasn't derived from "Java".
-
Pretty common technique to use such "cool" numbers for similar purposes. My old Tneo RTOS project still [uses 0xFEEDFACE to initialize tasks stack](https://github.com/dimonomid/tneo/blob/d4093f98d165702c21a2df58b2731f03622279c7/src/arch/cortex_m/tn_arch_cortex_m.h#L209), useful to see unused stack space in debugger. 0xCAFEBABE is indeed very…
-
A music format could definitely use `0xABBAACDC` ... covers a lot of bases there. For Ecstasy, we used `0xEC57A5EE`
-
The magic for the Linux device tree blob file format is d00dfeed which I find pretty funny
-
Right, `L` being interpreted as a suffix and not a hex digit.
-
Good ole' 0xBEEFBEEF would never steer you wrong
-
Personally for me, in principle I always enjoyed `0xFA1AFE1`, but the high-order nybble being unset always felt a bit displeasing; and, after I accidentally wrote `0xFA1AFEL` one time, which is neither the same value nor the same type, realised it might be higher risk than fun :)
-
I see what you did there. I was always partial to 0xDEADBEEF though
-
> I accidentally wrote 0xFA1AFEL one time, which is neither the same value nor the same type ...nor a valid hexadecimal literal ~~(unless this was C and it duly yielded a long of the value `0x00FA1AFE`?)~~
-
In a program for dumping N64 boot ROM, I had the exception handler write 0xCEDEC0DE to let the main entry point know it could find the dump in RAM.
All 3 developments of TIL: Why Java class files start with 0xCAFEBABE magic number →
RedditLobstersHacker News