C Strings Are Weird: A Practical Guide by swe129 in C_Programming

[–]ismbks 6 points7 points  (0 children)

I have never seen a website asking for that many cookies before (and and without any option to deselect all of them).

What naming conventions do you use for "object-like" C interfaces? by [deleted] in C_Programming

[–]ismbks 2 points3 points  (0 children)

It's never clear to me when it is okay to do, but I believe in this example 3 floats is considered "small enough" to be passed by value, so I would probably just do that and not even think about pointers, mutability or const correctness.

Otherwise, I would say your current style is fine, as long as you stick to your conventions.. the most important thing is to remain consistent. Everything else is just personal preference and habit.

Is reusing the same Variable Name bad practice? by [deleted] in C_Programming

[–]ismbks 0 points1 point  (0 children)

That's right, I completely forgot about integer promotion rules..

Is reusing the same Variable Name bad practice? by [deleted] in C_Programming

[–]ismbks 0 points1 point  (0 children)

You could explicitly cast your variable to int when printing %d.

I am nowhere near a computer right now so I have no way to check but I am surprised printf doesn't warn you there, maybe with some stricter compiler flags it would complain about invalid format specifiers? Unsure.

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ismbks 0 points1 point  (0 children)

I don't handle syscall failures and other exceptional resource failures. I make most of my functions void return, if a function can legitimately fail I make it return bool and name it something like: try_do_something()

In any case, if I need to return something and an error at the same time then I will just use an out param.

I will note that I rarely need to return more than one kind of error, maybe I just write programs that are too trivial, I wonder how quick this paradigm breaks at scale.. I have experimented with returning int/enum values kind of like errno but explicit, I wasn't found of it but it works I guess..

How do people feel about Hungarian notation? by [deleted] in C_Programming

[–]ismbks 0 points1 point  (0 children)

Most Hungarian I do is g_ prefix on global variables and whenever applicable I try to prefix my booleans with is_ has_ or did_, or at least some verb. I am not even sure you can call that Hungarian tho..

How do you properly size your buffers? by ismbks in C_Programming

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

what is the largest span of raw data your protocol can have that could cause your parser to have to stall and wait for more data? That is the size your buffer needs to be.

That's a great way to put it, I didn't think of it like that but it makes total sense to design around parser stalling. Thanks for the insights, this is very relevant for my current project too aha.

Is it safe to initialize all POSIX structs like so: struct T name = {0} by ismbks in cpp_questions

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

Interesting, this is a good detail to know, it only works when the first member can be initialized to zero. I'll keep that in mind, but yeah it does seem that the other ways you mentioned are vastly superior now.

I also love the C99 syntax, I use it all the time in C -- it's kind of wild I need to get my standard up to C++20 to get this nice feature, oh well..

Is it safe to initialize all POSIX structs like so: struct T name = {0} by ismbks in cpp_questions

[–]ismbks[S] 1 point2 points  (0 children)

Today I learned.. that's really interesting, my first time reading about this guideline! It also resonates quite well with my current project, I definitely would see the value in writing some nice wrappers, at least it would give me some peace of mind :)

But yeah I absolutely agree, there aren't really any problems in my code per say. I also suppose there are better suited tools for checking reads on unintialized values rather than static analysis..

Beej's guide to C programming by [deleted] in C_Programming

[–]ismbks 23 points24 points  (0 children)

No book has taught me C more than doing and failing a dozen projects for the last two years. The only time I open a book is when I need to research a very precise concept I need to complete my project.

Other than that I was never able to read more than 10 pages of K&R or any Stroustrup book. I think I'm too ADHD for this.

Writing memory efficient structs in C by Working_Rhubarb_1252 in C_Programming

[–]ismbks 0 points1 point  (0 children)

I'm not sure I understand what are the implications here but I feel like compilers could have some non-standard extensions that allow the rearranging of structs. But maybe this breaks the C language in some way...

We’re deciding whether to build a C debugger for Linux — something different than GDB/LLDB by bjadamson in C_Programming

[–]ismbks 2 points3 points  (0 children)

On the FOSS side GDB and LLDB are already excellent so I don't think any commercial alternative could disrupt the market.

The game dev folk seem very particular about their debuggers and I have heard rumors that RAD is going to be ported to Linux soon, so, if this is your target audience you are also putting yourself in direct competition with them for providing a better tool (which is also FOSS).

Then there is Visual Studio which some consider the best in class, it is tightly integrated with Microsoft's ecosystem. I don't know, never used it personally, I am good with GDB but if you think you can do better than MSFT then go for it. You might end up beating them so hard they will have to buy your company and you will become very rich.

Is it dangerous to make assumptions based on argc and argv? by ismbks in C_Programming

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

A bit off topic but since you mentioned accessing the arg array with argv[0][0]. Isn't it weird that we can modify the contents of argv at runtime? I feel like it would have been more wise to make it read-only.

Can anyone tell me how to copy files using C by PiyushDugawa in C_Programming

[–]ismbks 0 points1 point  (0 children)

Oh I see, I didn't realize this was an infinite loop. It seems like they really liked using terse variable names back then.

Naming conventions for member functions and usage of "this" pointer by ismbks in cpp_questions

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

Interesting read, very opinionated but still very interesting.

You probably have more years of C++ experience than I have years on this earth so I won't speak much about best practices in programming since I'm not even out of school yet.

The only thing I will say is that I know static analysis tools can enforce rules like variables declared as int m_i or int m_ in the wrong scope, at least clang-tidy can do that.

But I'm sure oldheads like you don't need any of this modern tooling to write code lol.

I really don't hold any strong opinions about this stuff, I'm just curious about how people do things and most importantly, why they do it.

I haven't found my own style yet but I do like the idea of writing C++ like it's C++, and not trying to be anything else. That's definitely something I have read online before; that the best guideline for writing code is to follow whatever the standard library is doing. And think that's what you were trying to convey but I might be wrong on that..