Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for Lundinâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Answer | — |
A: Renaming GNU/Linux tag to gnu I don't think GNU can be used as a stand-alone tag. Apart from the OS, GNU is also a tool collection of various programs, many used for programming, making is a very ambiguous tag which can't stand on its own. Any use of the tag needs to also specify what it's actually about: the OS or one of the ... (more) |
— | almost 3 years ago |
Comment | Post #286628 |
Ok, well... conditional compilation is always messy. I would consider solving this through version control and program design instead. As in, include a foo.h with the common interface, then link either A_foo.c or B_foo.c depending on version. (more) |
— | almost 3 years ago |
Comment | Post #286628 |
Not entirely sure what problem you are trying to solve, but is there any reason why you can't do `if (e) { _Static_assert(!e,"Called but not in binary."); } \` instead, something like that? To get a readable compile-time error instead of a mysterious link-time one? (more) |
— | almost 3 years ago |
Edit | Post #286593 |
Post edited: |
— | almost 3 years ago |
Edit | Post #286593 | Initial revision | — | almost 3 years ago |
Answer | — |
A: How to write a macro that discards the const qualifier, for any type? Ignoring the numerous forms of undefined behavior that casting away `const` might invoke, the blunt but simple and standard solution is just to cast to `(void)`. ```c char foo (const char str) { return (void)str; } ``` This is far more portable than gcc extensions like `typeof`. ... (more) |
— | almost 3 years ago |
Comment | Post #286575 |
@#53937 There are various tricks involving union type punning where the union members are pointers of different qualifiers. But that mostly relies on the C rules of effective type being underspecified in regards of type qualifiers, so I'm not sure if anyone could tell if it would be well-defined or n... (more) |
— | almost 3 years ago |
Comment | Post #286578 |
There's nothing in the C standard mentioning linking, so how and when these get linked is highly system-specific. On the average embedded system for example, each example will end up in true read-only memory at link-time. (more) |
— | almost 3 years ago |
Comment | Post #286575 |
Most of the time, you don't want to discard const qualifiers since that invokes undefined behavior in many cases. The appropriate solution is either to do a copy of the value or to reconsider your design. (more) |
— | almost 3 years ago |
Comment | Post #286440 |
@#36396 PID in the context of desktop/system programming means process identity. The less common meaning of it would be Proportional-Integral-Derivative controller. That's the two industry de facto standard meanings of the term - any other meaning isn't well established. In the context of Unix progra... (more) |
— | about 3 years ago |
Comment | Post #286372 |
The operator precedence will be the same as in basic math... so it's not even a programming problem. (more) |
— | about 3 years ago |
Comment | Post #285999 |
@#56561 This is about the code review category of this site so it doesn't apply. (more) |
— | about 3 years ago |
Comment | Post #283440 |
@#36396 If you are lucky then yes. With gcc you have to do `-Wall` to enable the warning for example. (more) |
— | about 3 years ago |
Edit | Post #283441 |
Post edited: |
— | about 3 years ago |
Comment | Post #286189 |
Btw I'm not saying that it shouldn't be used, I'm saying that it should be used with caution. It's an incredibly flawed function. At a minimum use a compiler which investigates the format string. Or perhaps generate the format string through some type safe interface like `_Generic` macros. (more) |
— | about 3 years ago |
Comment | Post #286189 |
@#8196 That would involve using OS-specific API though. Or in case of embedded systems, rolling out some UART or display driver manually. There's no universal replacement. Though console I/O is mostly a thing of the past, most people stopped using it around year 2000. (Programs with or without GUI ca... (more) |
— | about 3 years ago |
Comment | Post #285813 |
@#56533 No, in the first case you pass the array object and in the second case the function. As per various rules of parameter decay, the compiler will implicitly adjust them to pointers. Just as for example Java will implicitly adjust an object passed as parameter to a reference - same thing. (more) |
— | about 3 years ago |
Comment | Post #286191 |
In either of these scenarios, the correct place to check against null is _always_ where you have valid reasons to suspect it to get set to null (after a malloc call?) and only there. It is _never_ the correct place to check inside the completely unrelated library function `func` which has the purpose... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#8196 It isn't, it is the very same thing. This code `int* someptr = ...; /*...*/ if(!someptr) { ... } func(someptr); /*...*/ void func (int* someptr) { if(!someptr) { ...}` boils down to the very same thing as `int* someptr = ...; /*...*/ if(!someptr) { ... } /*some rows of unrelated code*/ if(!som... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#8196 So every 10th line or so we should check if all pointers in the current scope are null? Because that makes as much sense. (more) |
— | about 3 years ago |
Comment | Post #286191 |
Checking if you have the key before starting your car is perfectly reasonable. Checking if the car still has an engine, wheels and exhaust each time before starting it is not. What is one's reason for doing so, is there a notorious car part thief in the neighbourhood (valid reason) or is it "one cann... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#8196 Everyone is missing the point that checking for null _inside_ some generic function is always the wrong _place_. Checking for null elsewhere is perfectly reasonable and I never said otherwise. Unfortunately it would seem that the average reader here is of the PC programmer variety who has neve... (more) |
— | about 3 years ago |
Comment | Post #286189 |
@#36396 Looking them up is just a [man](https://linux.die.net/man/) away though. Some of these are rarely ever used even by C veterans. I don't think I've ever used `tmpfile` or `ungetc`, `signal()` is pretty much never used outside *nix systems and so on. (more) |
— | about 3 years ago |
Edit | Post #286195 | Initial revision | — | about 3 years ago |
Answer | — |
A: How can we grow this community? By having decent source code formatting that isn't completely inferior to other sites like Stack Overflow. We might want to post/view snippets longer than 13 lines without suffering some scroll wheel. See my feature request here. My first impression when coming to any Codidact site requiring sour... (more) |
— | about 3 years ago |
Comment | Post #286189 |
@#36396 "Family of functions" means that there is `atoi` and `atof` and `atod` etc, a bunch of very similar functions with slight differences when it comes to types/parameters. And there's a corresponding more suitable family of `strtol`, `strtof`, `strtod` and so on. Similarly there is `printf`, `f... (more) |
— | about 3 years ago |
Comment | Post #286193 |
"Defensive programming", as in applying numerous error checks even in cases that theoretically shouldn't fail, might be a good idea. However, such error checks should be located near the place where one might suspect that the error appears (user input, buffer copying etc), and not in some unrelated l... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#8153 Ah yeah, silly little bug. It's been fixed, thanks. (more) |
— | about 3 years ago |
Edit | Post #286191 |
Post edited: Fixed a bug |
— | about 3 years ago |
Comment | Post #286191 |
@#53305 So now I'm not only waiting for you to explain how a C function should do bounds checking of its array parameter, I'm also waiting for you to explain exactly how `memmove_s` checks it's parameters against null, contrary to the run-time constraints in K 3.7.1.2 I just quoted. Or we could just ... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#53305 It's not "whatever", you criticise my post and down vote it with the and claim that functions should do bounds checking, which I still don't know what it has to do with null checking. I'm happy to get _constructive_ criticism but this isn't it. As for the optional annex K bounds checking inte... (more) |
— | about 3 years ago |
Comment | Post #286191 |
@#53305 How is that even related? Also I don't understand what you are talking about: either a function gets an array size passed, in which case the caller has to get it right, or it doesn't get an array sized passed, in which case no can do. Either way, a function in C cannot do meaningful bounds-ch... (more) |
— | about 3 years ago |
Edit | Post #286191 |
Post edited: |
— | about 3 years ago |
Edit | Post #286191 |
Post edited: |
— | about 3 years ago |
Edit | Post #286191 | Initial revision | — | about 3 years ago |
Answer | — |
A: Should I check if pointer parameters are null pointers? The kind of comments telling you to add checks against null are typically coming from programmers mostly used to deal with higher level programming languages. They think that generally, more explicit error handling is always a good thing. And that is true in most cases, but not in this one. The sp... (more) |
— | about 3 years ago |
Edit | Post #286190 | Initial revision | — | about 3 years ago |
Question | — |
Should I check if pointer parameters are null pointers? When writing any form of custom function such as this: void func (int a, int b) Should I add code to check if `a` and `b` are null pointers or not? if(a == NULL) / error handling / When posting code for code reviews, one frequent comment is that such checks against null shoul... (more) |
— | about 3 years ago |
Edit | Post #286189 |
Post edited: |
— | about 3 years ago |
Edit | Post #286189 |
Post edited: |
— | about 3 years ago |
Edit | Post #286189 | Initial revision | — | about 3 years ago |
Answer | — |
A: Which functions in the C standard library must always be avoided? Standard library functions that should never be used: setjmp.h - `setjmp()` Together with `longjmp()`, these functions are widely recogniced as incredibly dangerous to use: they lead to spaghetti programming, they come with numerous forms of undefined behavior, they can cause unintende... (more) |
— | about 3 years ago |
Edit | Post #286187 | Initial revision | — | about 3 years ago |
Question | — |
Which functions in the C standard library must always be avoided? It would seem that the C standard library is a collection of diverse functions that pretty much just ended up in the standard by tradition or "accident", rather than through some careful plan or rationale. During standardization of ANSI/ISO 9899:1990, they just grabbed a bunch of existing library fun... (more) |
— | about 3 years ago |
Comment | Post #286152 |
The thought I had when raising this question was mainly how much research effort we should require. SO went from "you have to at least understand a minimum of the topic" to "ask anything you want" and the site got IMO much worse because of it. If we aren't expecting any research effort then posters e... (more) |
— | about 3 years ago |
Edit | Post #286142 | Initial revision | — | about 3 years ago |
Answer | — |
A: C++ exit code -1073740940 C++ doesn't have error codes/exit codes other than `return 0;` / `EXITSUCCESS` / `EXITFAILURE`. The code you are getting is from the OS when your program crashes from a run-time error. `-1073740940` is unhelpful gibberish, you need to convert this from 2's complement 32 bit into hex. Then you get ... (more) |
— | about 3 years ago |
Edit | Post #285998 |
Post edited: Better title |
— | about 3 years ago |
Comment | Post #285999 |
@#8046 Well 400 lines of very compact and detailed code with lots of comments might go as far as 30k characters... maybe. If we are looking for some worst-case number, I'd say a reasonable upper limit might be something like 1k lines 80 characters each = 80k. Larger than that and it won't be fun to r... (more) |
— | over 3 years ago |
Comment | Post #285999 |
Seriously, 400 lines of code is not much, the average source file is some 200-1000 LoC and a medium-sized project has maybe 50 such files. Sure, a whole project like that would be too much, but why wouldn't the site be able to take a 400 LoC post? (more) |
— | over 3 years ago |