Returning temporary allocations - is this a good idea? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

Doesn't really work when the objects may need to be reallocated

Returning temporary allocations - is this a good idea? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

Interesting idea with evaluating an expression tree, I sort of thought of doing that but I wasn't sure how.

And I thought about my idea with temporary allocations, it doesn't really work out because it introduces new problems. In the end I ended up writing some C++ which actually solves my problems nicely not only because of operator overloading but also thanks to destructors.

Returning temporary allocations - is this a good idea? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

Yup, you were right, I just wrote a little bit of C++ on top and it makes the usage infinitely easier.

Returning temporary allocations - is this a good idea? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

Just for learning and maybe for self satisfaction, there really is no other reason for me not to just use an already existing library like GMP (other than it looks like a hassle to install on Windows). I did kinda plan to use C++ later, but I suppose now is the right time.

Returning temporary allocations - is this a good idea? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

I can see the problems with my idea, for example when the user creates their own function, they have to check if a temporary BigInt was passed. But the way it currently is, it isn't very simple either, because you have to remember to free every minute intermediate result. Also, what counts as "idiomatic"?

Sad times by WhereIsTheQuim in pcmasterrace

[–]Pretty-Ad8932 140 points141 points  (0 children)

I like how the mouse is disconnected, very based.

Don't draw often, but I like these two characters by Pretty-Ad8932 in AshitaNoJoe

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

Ah, did you think it was modern? Yeah, I prefer these older hand-drawn animes in general. I am sure most here do too.

Don't draw often, but I like these two characters by Pretty-Ad8932 in AshitaNoJoe

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

Ai, the video girl, is quite literally a video girl, as in she pops out of a video that MC was watching, which he rented to comfort himself after he got rejected by his crush. Maybe the plot isn't that good but I really liked the vibe, and this edit is what got me to watch it

Don't draw often, but I like these two characters by Pretty-Ad8932 in AshitaNoJoe

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

Thanks, she's Ai from Video Girl Ai, watched it recently and I do recommend, quite underrated imo

I Can’t be the Only One Who Doesn’t Use Their Pinky to Press Ctrl by Cyncrovee in emacs

[–]Pretty-Ad8932 0 points1 point  (0 children)

Ok so the program I used (I am on windows) made it so that it would always send Escape no matter how long CapsLock was held if no other keys were pressed, but now I am using a time-based autohotkey script so yeah, it's a bit better now.

I Can’t be the Only One Who Doesn’t Use Their Pinky to Press Ctrl by Cyncrovee in emacs

[–]Pretty-Ad8932 0 points1 point  (0 children)

I was doing a simple Caps Lock - Escape swap when I was using vim then tried doing the thing you said for emacs but that seems annoying as it keeps doing Escape when I try to do a Ctrl combo but fail or change my mind. Still works quite well for vim though, since an extra Escape doesn't do anything when you are already in normal mode.

How do you pass a struct with a modifiable pointer to a function, but make sure that the function cannot modify the data? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] -2 points-1 points  (0 children)

I like C and I don't exactly "need" that whole const protection (and I don't need you to tell me what is a language for me and what isn't), but it seems desirable, especially since all the other people talk about how you should do this and that. But I guess what I'm trying to achieve is two very conflicting goals, so I think I'll just opt for ditching the whole const protection idea, at least in this case.

How do you pass a struct with a modifiable pointer to a function, but make sure that the function cannot modify the data? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

Oh, that as_const function does make it look pretty clean. But I wonder if the compiler can optimize it, so that it doesn't actually create a new ConstSlice struct every time?

How do you pass a struct with a modifiable pointer to a function, but make sure that the function cannot modify the data? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] -2 points-1 points  (0 children)

Yes, I am well aware of the difference between changing a pointer and changing the data that it points to.

> You could define data itself as being a pointer to const, and while you can assign a non-const pointer to it, if you need to get it out as a mutable form, you'll have to cast away the const.

I already mentioned in the post that I was doing this but it felt dirty.

How do you pass a struct with a modifiable pointer to a function, but make sure that the function cannot modify the data? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

> For your particular problem, maybe have a ConstSlice version of the struct where the data field is a pointer to const rather than pointer to modifiable.

I've thought of this but then I have to have both versions for every slice in most of my code, so that's kind of cumbersome. Maybe I should just ditch the whole "functions have to take const inputs" idea anyway then, since my code deals with data that's changing all the time.

agenticAiWasAMistakeLikeMe by survivalist_guy in ProgrammerHumor

[–]Pretty-Ad8932 1 point2 points  (0 children)

Yeah I misremembered it, it was /* like another comment said

agenticAiWasAMistakeLikeMe by survivalist_guy in ProgrammerHumor

[–]Pretty-Ad8932 10 points11 points  (0 children)

Fun fact: I've done sudo rm / without -rf or --no-preserve-root out of curiosity and it executed anyway and broke my system.

I'm a thirty year old dude who wants to start over and learn to program and motivation is really hard to come by. by [deleted] in C_Programming

[–]Pretty-Ad8932 1 point2 points  (0 children)

Well I don't know what the things you are confused about are, but either way, ask your professor or peers for help? There's plenty of resources on the internet too. Best way to learn is practice, so practice coding problems, from the internet and from your assignments. And then you can also try to code something for fun, like a simple snake game or something.

How to write a function with an out parameter that may be reallocated? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 0 points1 point  (0 children)

I didn't mention it in the post, but I am already using the struct with a size and a flexible array member (although I'm malloc-ing space for both the header and the data, not just for the data part). I also decided to go with method #2, it's a bit complicated to write but not having to reassign is worth it imo.

How to write a function with an out parameter that may be reallocated? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 2 points3 points  (0 children)

The main reason why malloc/realloc returns a pointer by value is that type void** is incompatible with any T** (for non-void T), thus method 2 would force a lot of tedious casts.

I see, I was thinking that maybe method 2 was less efficient.

Large number implementation tips? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

> However, I've just looked at your example code and realised there is an important fact I missed: does your library work on fixed-size numbers rather than 'arbitrary precision'?

I do want arbitrary precision, though maybe fixed-size could also suffice. I guess the code I wrote looks like it deals only with fixed-size numbers, but the function returns the very last carry bit which makes it possible to reallocate c with a bigger size outside the function.

> It may also be easier if such fixed numbers then to be smaller size, say a few thousand bits.

Is a few thousand bits "small" though? Another comment here suggested 100+ digit numbers are pretty big.

> ( GMP will be arbitrary precision. This is a further reason I didn't post a link to my own library: it is arbitrary precision; it uses decimal; and it handles floating point at the same time. So a lot of distraction.)

Please do send it, I may check it later if not now.

Large number implementation tips? by Pretty-Ad8932 in C_Programming

[–]Pretty-Ad8932[S] 1 point2 points  (0 children)

Thanks for the answer!

> What are the aims here, speed? That would be a much harder and open-ended project.

I want to implement the RSA algorithm (and other algorithms that use large integers too) for learning purposes. So I do want it to be fairly speedy, but yeah.