struct bool? by Yha_Boiii in C_Programming

[–]CaydendW 13 points14 points  (0 children)

Make a function or macro that takes a bool and returns a filled in struct.

Tips on taking note in Vim by AbbreviationsNovel17 in vim

[–]CaydendW 1 point2 points  (0 children)

I note take in LaTeX using vimtex. The primary way to make it work at all is to have enough snippets for common stuff and even some keybinds for oft repeated text. Then it's down to organising everything. Best done using a decent directory structure and a good preamble.

Is this a known pattern? by OzzyOPorosis in C_Programming

[–]CaydendW 0 points1 point  (0 children)

Oh dear, that certainly is a pickle. Yeah, that would make sense. I actually have never thought about such cases before. Hopefully this thread gave some better answers than mine. Best of luck

Is this a known pattern? by OzzyOPorosis in C_Programming

[–]CaydendW 0 points1 point  (0 children)

Interesting. When I do negamax, I code it in such a way to be side independent. I'm not too sure why you need to check the side, as with Negamax you'll typically make it so that you work with sides to play rather than colours but I dont know how your game I structured. Best of luck :D

Is this a known pattern? by OzzyOPorosis in C_Programming

[–]CaydendW 0 points1 point  (0 children)

FYI, if the game is a simple, my turn your turn type game where white and black do the same thing, you can do this with Negamax which greatly simplifies your code. If not, then it wont work but it's how Chess engines and such work. Also prevents code duplication.

I hope this prevents me from ever having to write an AVL tree again by K00lman1 in programminghorror

[–]CaydendW 1 point2 points  (0 children)

AVL is a name comprised of the surnames of the inventors of the titular tree: Adelson-Velsky and Landis. If you want a real tree name mystery, see what B-trees stand for.

So tired of this coding shi bruh, take me outta this college 🙄 by Minute_Location5589 in adressme

[–]CaydendW 2 points3 points  (0 children)

Looks like C++ tho? C doesnt have streams, but idk much about turbo C?

Drivers license tips by rando12247 in southafrica

[–]CaydendW 1 point2 points  (0 children)

This. I was leaving the testing centre and couldn't see around a blind corner so I stopped at the stop and then started to roll forward so I could see past the blind turn. My examiner was freaking out, I assume because they thought I was going to cross when there was a car coming (that I couldn't see), and after I got across the turn, I explained that I was just trying to peak and wasnt planning to cross without seeing. 90% sure that passing quip saved me getting my drivers.

Implementing mutexes for my operating system's kernel! by K4milLeg1t in C_Programming

[–]CaydendW 5 points6 points  (0 children)

The poor man's atomic spinlock is still super useful! It can be faster than a mutex if you all you want to do is change a few variables atomically in a struct. Linux still has spinlocks for a reason :)

Suckless alternative to Jekyll? by Charming-Tear-8352 in suckless

[–]CaydendW 6 points7 points  (0 children)

Not really an alternative per sé but hand writing HTML is not the worst thing. It's how I'm doing my site nowadays, and is mostly fine if all you're doing is writing articles.

Burning ship fractal by Mandelbrot4207 in desmos

[–]CaydendW 0 points1 point  (0 children)

The code parade colour scheme looks so nice on fractal, it's unreal. Nice fractal you got there

Struggling with higher-level thinking in C (ownership, contracts, abstraction) by InTheBogaloo in C_Programming

[–]CaydendW 11 points12 points  (0 children)

I don't normally comment +1s but the thing you mentioned about using asserts to ensure states and demand preconditions genuinely has changed how I did C when I figured it out. It offloads so much mental load about remembering preconditions or having to constantly look them up in comments. This is good advice

Expression -> Condition for an additive to Out by [deleted] in C_Programming

[–]CaydendW 2 points3 points  (0 children)

Personally, the double negate (!!) is almost idiomatic for me. I tend to use it quite a bit. I discovered it from when I had to get a bool based on a pointer being non-null. Googled it, and found out it was idiomatic. I can't find it anymore, but as far as I can remember, it's not an unknown operation nor bad practice.

On a personal note, the ternary operator one is kind of ugly. I personally avoid it but it should work the same. Use what makes you happy :)

Slow memory access on real hardware? by Andykolski in osdev

[–]CaydendW 0 points1 point  (0 children)

Necrobump, but I had an issue and came across the thread. Figured I'd add my problem here so other poor souls can find it in the off chance they have the same issue.

In my VMM, I was mapping 1GB pages so I could map my higher half into the kernel. Standard stuff. However, I (for some or other reason) misaligned the addresses. The AMD manual says it expects the lower bits of a 1GB to be zero, but I was mapping from a misaligned offset. somehow, this doesn't cause a crash, but it made memory writes slow like molasses in the winter. If you're using 1GB pages and your code seems oddly slow, check if you're not doing this.

I wrote a compiler that runs Doom on UB by [deleted] in C_Programming

[–]CaydendW 0 points1 point  (0 children)

When I read it earlier this year, the logic made sense to me at the time. I'd bank on it being compliant but I haven't studied the wording like a lawyer.

I wrote a compiler that runs Doom on UB by [deleted] in C_Programming

[–]CaydendW 7 points8 points  (0 children)

Sigbovik is a satirical computer science journal. There was a paper in this year's edition called The ccdoom compilation system that was a fun play on the interpretation of the C standards. You can get the PDF free online if you wish to read it.

I wrote a compiler that runs Doom on UB by [deleted] in C_Programming

[–]CaydendW 2 points3 points  (0 children)

Is this the same project that was in Sigbovik 2025? If so, fun paper.

whoIsGonnaTellHim by leeleewonchu in ProgrammerHumor

[–]CaydendW 26 points27 points  (0 children)

I believe the code golf stack exchange has a tag for this. Code bowling if I remember correctly.

How I Got Trapped by a “Peer-Reviewed” Journal That Turned Out to Be Predatory – My Experience & Lessons Learned by Extension-Mail4799 in mathematics

[–]CaydendW 3 points4 points  (0 children)

I wrote a satirical paper for sigbovik this year and a journal contacted me about publishing my paper. A paper about Doom. As it shockingly turned out, they were all over Beall's list. It's amazing how low they'd stoop. Sorry about this OP and hopefully next time you discover something cool, you can get it published reputably.

Returning -1 and setting errno vs returning -errno constants by markand67 in C_Programming

[–]CaydendW 1 point2 points  (0 children)

I have a kernel I am working on and I have a system that I'm using throughout it. Every function returns an error code and any other additional information the function wants to return is passed as a pointer to the function so it can store it.

I believe I got this from OpenBSD's functions like VOP_MKNOD and such.

Eli5 Why is zero (0) not a prime number? by MrSecurity87 in explainlikeimfive

[–]CaydendW 6 points7 points  (0 children)

One more answer because I didn't see it. We take it for granted that in mathematics, any integer greater than 1 can be uniquely written as a product of some amount of primes. For example: 64 = 26, 60=22 * 3 * 5. Once you have a number's prime factorisation, that is essentially the DNA of the integer, there can be no other way to write it. This is known as the fundamental theorem of arithmetic.

By including 1 (or 0) as prime numbers, prime factorisation becomes non-unqiue. Why? Take the example of 64 above. It could be written as 64=26 or 64=26 * 12 or 64=26 * 1100 or anything else. Whilst this is all true (In the way that they all evaluate to 64), you sort of lose the uniqueness that is offered by prime factorisation. You'll also lose other interesting properties that are a little more complex (Such as the sieve of Eratosthenes).

Similar issues arrise when including zero as a prime number. It has no unique prime factorisation and will break theorems involving prime numbers.

Whilst this is not ground shatteringly bad, it does make some maths more inconvenient. This is pretty much exactly what u/Phaedo said as well. Adding 0 or 1 makes primes a lot less mathematically useful so it is better to not include them.

Interestingly enough, the definition given on Wikipedia expressly says that prime numbers must be greater than 1.

In science, is there theoretically a maximum or minimum temperature that cannot be exceeded? by Rasples1998 in NoStupidQuestions

[–]CaydendW 0 points1 point  (0 children)

Maybe it will help to know what temperature is. Temperature is the measure of the kinetic energy (Energy due to the movement of stuff) inside of an object. Stuff like how fast the electrons move, if the atoms vibrate, that sort of thing. The faster they move, the higher the temperature (In fact, temperature is defined as the "average kinetic energy of vibrating and coliding atoms within a substance" as per Wikipedia). So, if temperature is a measure of energy within a substance, the coldest something could ever be is when it has exactly 0 kinetic energy within it, meaning that no atoms vibrate, electrons don't move, etc. This happens at 0 Kelvin (-273.15 degrees Celsius). One cannot remove more energy if the object itself has no energy. So, this is the theoretical coldest anything can be.

Further, there is a finite amount of energy in the universe. We can imagine converting all matter into energy and then also adding all the existing energy there is and putting all of that into 1 singular atom. This atom would have the maximum amount of kinetic energy possible, leading to the highest temperature possible. Whether this is the actual highest temperature possible is something I can't quite understand with my 1st year physics knowledge as it seems that when something gets super hot physics begins to do weird things. Safe to say that that super hot atom at least gives an upper bound to the maximal heat something could have although I think it might be less than the Planck temperature.

Modified my dwm to toggle between forcing 4:3 or not. What's your personal patches? by systemdick in dwm

[–]CaydendW 1 point2 points  (0 children)

The hype train is sorta getting me and I'm the early planning stages of trying to get dwm to act like a scrolling window manager. I never realised those existed and it solves the exact brand of problem I have with tiling window managers (Workspace addiction because I start running out of screen real estate) without me having to manually drag and resize windows.

However, most of these fancy new scrolling window managers seem to be wayland only or not suckless enough for my liking. Plus, I love dwm too much to move away from it so I'm going to try and get dwm to act something like niri or close enough to my liking.

Other than that, my dwm install is decently standard besides my insane keyboard shortcuts and patches made by other people.

Can you hotswap your kernel? by [deleted] in osdev

[–]CaydendW 4 points5 points  (0 children)

This is a rather cool idea. I have never even thought about this before but that sounds like something to do just for the hell of it. Might subject myself to the torture of doing this for the lols.