Possible review of small C programs
-
- Posts: 4
- Joined: Tue Apr 29, 2025 7:29 pm
- Libera.chat IRC: empathy_monster
Possible review of small C programs
Hi there. I've visited osdev (dot) org quite a few times in the past year, mostly out of curiosity, as I'm not an experienced programmer, but never used the forums. In a nutshell, my question is if this is a good forum to get feedback on my C programs in general. I don't want to use reddit. As a quick background, I've taken Python and Java in college, so I'm not a completely inexperienced programmer, but I'm definitely still in the intermediate end of of learning C. From my college courses, I learned to first plan my programs before writing any code, and to thoroughly document my code. Whenever I use a stdlib function, I usually comment it with the manual page and the section in the GNU C Introduction and the GNU libc reference manual where I obtained the information. I have looked up the Linux coding standards for C formatting, and that's generally what I try to follow. If that's allowed, it's also something that I would not abuse by too frequent postings, as I completely understand people are busy and their feedback comes free. Or, perhaps, if someone might be willing to let me pm them, say, a program every two or three weeks that's ~200 loc or so. Mostly what I'm interested in is, for example, things like the rationale over using something like stpcpy() over strcpy(), if I'm handling errors properly, what's the rationale for using this library function or system call over that one, things of that nature. As a further note, I have a copy of Modern C by Dmitrovic, and I wouldn't say that I necessarily have it memorized, but I am thoroughly familiar with all of the material. Thanks so much.
Re: Possible review of small C programs
Some days I wonder if this is AI or if people really are like that nowadays.
As for posting to the board: It is not like we are usually drowning in messages. We have a "General Programming" board for stuff like that. Just send stuff, maybe someone will bother with it.
Talk about overkill. If you really did that, you wouldn't be able to see the source code beneath the mountains of comments.empathymonster wrote: ↑Tue Apr 29, 2025 7:52 pm Whenever I use a stdlib function, I usually comment it with the manual page and the section in the GNU C Introduction and the GNU libc reference manual where I obtained the information.
stpcpy() is like strcpy() but with a sensible return value (pointer to the end of the destination string). Neither is terribly good. Rule of thumb: A function that takes a pointer without a length is probably not good. Yes, that means that strlen() is not a good function. strnlen() is better, but only in POSIX, not ISO-C. But you can build strnlen with memchr().empathymonster wrote: ↑Tue Apr 29, 2025 7:52 pm Mostly what I'm interested in is, for example, things like the rationale over using something like stpcpy() over strcpy(),
As for posting to the board: It is not like we are usually drowning in messages. We have a "General Programming" board for stuff like that. Just send stuff, maybe someone will bother with it.
Carpe diem!
-
- Posts: 4
- Joined: Tue Apr 29, 2025 7:29 pm
- Libera.chat IRC: empathy_monster
Re: Possible review of small C programs
I don't understand why commenting my code with the section in the glibc ref manual would make you think it's AI. It's mostly for my own reference.
-
- Posts: 4
- Joined: Tue Apr 29, 2025 7:29 pm
- Libera.chat IRC: empathy_monster
Re: Possible review of small C programs
I do appreciate the reply though. I'll try to keep any comments to a minimum then if I do post something.
Re: Possible review of small C programs
There’s no problem, as far as I’m concerned, with posting whatever you like in the General Programming forum. The proof of the pudding is whether you get any answers or not. No-one is forced to answer, or read, posts so don’t worry about them being too busy; if that’s the case they just won’t respond. The only problem would be creating too much noise by posting lots of trivial questions. It doesn’t sound as if that would be the case.
Commenting - how much or how little - is a matter of personal preference, although in a group programming effort you would need to establish common rules. Most amateur programmers under comment, which generally comes back to bite you when you later look at the code. Use whatever level of commenting helps you most.
Commenting - how much or how little - is a matter of personal preference, although in a group programming effort you would need to establish common rules. Most amateur programmers under comment, which generally comes back to bite you when you later look at the code. Use whatever level of commenting helps you most.
Re: Possible review of small C programs
Wasn't that. More the general lack of structure and the rambling evident in the OP. I open up the topic and am immediately greeted by a wall of text, that's rarely a good sign.empathymonster wrote: ↑Tue Apr 29, 2025 9:23 pm I don't understand why commenting my code with the section in the glibc ref manual would make you think it's AI.
True, but hiding the actual implementation beneath pages and pages of comments is probably also not good. I do like the comments in the musl source code, which explain the reasons rather than the implementation details, e.g.
Code: Select all
/* The main program must be relocated LAST since it may contain
* copy relocations which depend on libraries' relocations. */
reloc_all(app.next);
reloc_all(&app);
Carpe diem!
Re: Possible review of small C programs
I take it that you are not a fan of Knuth’s literate programming. He’s one of my coding heroes.
Any decent programming editor should let you collapse comments (functions, blocks, etc.) so that you can see the wood for the trees.
Any decent programming editor should let you collapse comments (functions, blocks, etc.) so that you can see the wood for the trees.
-
- Posts: 4
- Joined: Tue Apr 29, 2025 7:29 pm
- Libera.chat IRC: empathy_monster
Re: Possible review of small C programs
Thank you for the replies. I was trying to be as brief, but also as detailed as possible with my original post. I didn't want to come off as someone who has absolutely no idea about programming, bc I know more experienced people tend to frequent this forum. When I said I comment my code with the manual page, I didn't mean I literally paste the entire manual page into a comment. That'd be silly. I just make a note of which page I got the info from so that I can pull it up if I need to when I come back to that section code. Same thing with a glibc reference. It's just something simple like 11.2.2 file name resolution, page 268. And if for whatever reason there's what I feel is a particularly important bit of text, I'll put that in there, but it's usually no more than a sentence or two, similar to the musl example you gave. Anyways though, we don't have to continue on with that point. I read this post before posting: viewtopic.php?t=16944 , which is the forum rules - required reading, and even the link it suggests, How To Ask Questions the Smart Way, by Eric Raymond. I went through the forum FAQ and read what I thought were immediately relevant topics for me. In short, I'm trying to make an effort and wanted to try to reflect that in my post.
Re: Possible review of small C programs
I didn't think you did. Well actually, I did for half a second, then I realised.empathymonster wrote: ↑Wed Apr 30, 2025 11:00 am When I said I comment my code with the manual page, I didn't mean I literally paste the entire manual page into a comment. That'd be silly.


Thanks for reading all that on how to ask questions well, it helps a lot when people do.



Would you like this thread moved to General Programming?
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie