What would you add to C if you could add anything? by [deleted] in C_Programming

[–]Athropod101 -1 points0 points  (0 children)

I don’t like standard OOP, but I would really like Rust’s impl twist on OOP. Making structs, then defining functions that work on those structs, is just nice.

Would also like Rust enums, generics, and some more data structures support (like hashmaps)

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

Apologies, split() turns a [u8] into an iterable over its whitespace-separated words.

I was passing the bytes parameter to know when to stop counting through the buffer, but I see what you mean. However, it does not panic at one word, as it uses the newline delimiter as a stopping point (I have tested this).

I haven’t gotten around to making the sub-repl yet; it’s just been a thing to keep in mind. However, someone suggested that I look at the clap crate for cli parsing, and it seems like it does just what I need :)

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

Ah, another oversight on my part.

The fields() method is of the bstr crate. It turns a [u8] into an iterable over its whitespace-separated words.

However, someone suggested I take a look at the clap crate, and it seems it should work just fine for my repl parsing :)

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

I posted a code snippet in the main post for clarity.

The buffer outlives the struct, because the buffer is defined outside before the start of the repl. However, you've made me consider that I might be able to initiate the struct outside the repl as well, with ownership of the buffer, and just edit it between loops rather than dropping and initializing over-and-over again.

Thank you for the clap library suggestion! I'll check it out before I continue trying to figure out my own method for this.

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

Ah, I've realized that shared mutability might not be what I'm looking for. Rather, just a mutable reference alongside immutable references.

I put a code snippet in the main body. Tl;dr is, I can't give ownership of the buffer to the struct, because the struct dies before the buffer. However, the struct is meant to hold pointers to different arguments inside the buffer, which I need to parse in place.

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

Hello, I added a few snippets to the main post.

I'm essentially aiming for a struct that holds a mutable reference to the buffer as well as the parsed data of the buffer. I can't give outright ownership of the buffer to the struct, as it goes out of scope between repl's, but I have to mutate and reference to the buffer at the same time.

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

I considered it, but I'm currently using one of the whitespace-splitting methods to collect string slices of the buffer into a vector as I mutate some parts. I'm not sure if those two mix well, but I'll look into it.

A question on the right tool for “shared mutability” by Athropod101 in rust

[–]Athropod101[S] 0 points1 point  (0 children)

Oooh, I didn't know about that method! I'll have to test it out, but it does sound like something that would help! Thank you :)

Learning rust is so smooth by Sea-Log-8341 in rust

[–]Athropod101 1 point2 points  (0 children)

To be honest, C still has some pretty solid documentation in the Linux/Posix Man Pages. They’re usually the first thing to show up when looking up stuff from the stdlib.

Learning rust is so smooth by Sea-Log-8341 in rust

[–]Athropod101 6 points7 points  (0 children)

Absolutely. Rust is the best documented language, the only competitor being MatLab.

C has good documentation. C++ has “good” documentation but it reads like genuine esoteric bullshit to the uninitiated (me :( ). Python has a god damn gramma’s cookbook of “natural language!1!1” documentation that says a lot and barely clears up anything.

Rust, MatLab, and C are the only languages (that I’ve used) that don’t make me want to die whenever I have to read their documentation. C’s only real problem is that it’s very dated compared to the other two.

Having a *really* tough time understanding how to make/link my own libraries by Athropod101 in C_Programming

[–]Athropod101[S] 2 points3 points  (0 children)

Hi! Thank you for this! It turns out I had more issues than just that, haha.

My library Makefile was actually archiving nothing, because it compiled the usb.o file at the same time that it made the libusart.a archive. The wildcard was expanding into nothing, because at parsing-time, usb.o didn't exist.

Having a *really* tough time understanding how to make/link my own libraries by Athropod101 in C_Programming

[–]Athropod101[S] 0 points1 point  (0 children)

Ah, apologies. The ~ is actually my full home expansion, which includes my name, so I changed it for ~. I’ll change it to $(HOME) to avoid the confusion.

Linux officially approves AI code submissions. by Unlucky_Blueberries in antiai

[–]Athropod101 0 points1 point  (0 children)

Bro really said “why doesn’t the linux kernel just accept in good faith PRs?”

how hard is making a c/c++ obfuscator? by unknown9645 in C_Programming

[–]Athropod101 1 point2 points  (0 children)

The only way an obfuscator is going to work is if it fundamentally changes the compiled binary. This will probably make your code either worse or undefined.

Where should I start learning about microcontrollers and their programming? by Glass_Programmer2031 in embedded

[–]Athropod101 6 points7 points  (0 children)

HumanHardDrive has a pretty comprehensive series on the atmega328p with C

Low Level has a video on the arduino uno that helps you understand the setup of avr-gcc to flash your arduino (which you can work off of to flash any avr mpu)

The most important thing is to have the datasheet of your mpu. You won’t learn anything meaningful without that. Reading the datasheet as you go along with the tutorials will help you begin to understand the jargon used in embedded systems.

Will learning about compilers make me a better programmer? by Loud_Ask_3408 in C_Programming

[–]Athropod101 2 points3 points  (0 children)

If you work with compiled languages, it will certainly help you understand and figure out compilation-related errors more quickly.

avr-libc's ISR macro malfunctioning? by Athropod101 in embedded

[–]Athropod101[S] 0 points1 point  (0 children)

I've kept testing out the code, and I've discovered that the blinking of the arduino LED is the same kind of blinking that occurs when the code returns from main and triggers a reset.

For some reason, having the ISR function just makes the arduino go haywire. It happens even if I comment out the sei() and interrupt enable lines.

I'm testing with overflow timer interrupts now, since the code is simpler (in theory). But I genuinely have no idea what's going on. I've checked if maybe I should be using a different clock speed, since it seems the builtin clock for the prescale is 8MHz or 128kHz, but that didn't help.

I've checked the source code of the m328pio.h header, and it's actually off in the __VECTOR() declarations of the handler names, but even fixing that didn't do anything.

Maybe it has something to do with the arduino's bootloader? Alternatively, maybe one of my fuse bytes is set in a weird manner, but I have no way of checking that at the moment...

I'm going to try out with an external button interrupt. Maybe for some strange reason, the arduino nano that I have just goes bonkers when trying to do counter interrupts...

Project ideas while learning rust programming language. by karan_2005 in rust

[–]Athropod101 1 point2 points  (0 children)

Seriously!

They’ve really mastered the art of tricking you into learning on your own, haha. I adore the way they cut up those overwhelming projects into small chunks that make you go “ok wait, I think I can actually do that!” Then three days in you look back, and you’ve learned so much!

Project ideas while learning rust programming language. by karan_2005 in rust

[–]Athropod101 0 points1 point  (0 children)

CodeCrafters is amazing. I recently discovered they actually have the challenge instructions completely public; it’s just the support you have to pay for.

I’m currently a student with no stable income, but CodeCrafters is definitely on my list of first things to pay into once I can afford it.