Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

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
Edit Post #286191 Post edited:
about 2 years ago
Edit Post #286191 Post edited:
about 2 years ago
Edit Post #286191 Initial revision about 2 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 2 years ago
Edit Post #286190 Initial revision about 2 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 2 years ago
Edit Post #286189 Post edited:
about 2 years ago
Edit Post #286189 Post edited:
about 2 years ago
Edit Post #286189 Initial revision about 2 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 2 years ago
Edit Post #286187 Initial revision about 2 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 2 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 2 years ago
Edit Post #286142 Initial revision about 2 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 2 years ago
Edit Post #285998 Post edited:
Better title
about 2 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)
about 2 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)
about 2 years ago
Comment Post #285974 As a side note regarding embedded systems and main(), there's an issue where C++ claims that if main() is defined, it must be declared as int main() and I don't even think they made an exception for freestanding systems. In that case `noreturn` might save the day. That doesn't apply to C however, wh...
(more)
about 2 years ago
Comment Post #285974 @#53937 I wouldn't dare say anything about ABI compatibility between all *nix systems that have implemented pthreads over the years. Just take x86_32 Linux vs x86_64 Linux as the most obvious example.
(more)
about 2 years ago
Comment Post #285974 @#53398 Again, you can't do that for the same reasons as in my previous comment - calling convention. If you specify a return type but don't return, you risk tricking the compiler into thinking it should push/pop items on the stack which are never pushed/popped there by the function. This is also the...
(more)
about 2 years ago
Comment Post #285974 @#53937 Never the less, it is bad practice not to clean up your own mess no matter what the OS does. Executing such clean-up code is also an excellent way of surfacing dormant bugs elsewhere in the application (`free()` crashing etc).
(more)
about 2 years ago
Comment Post #285974 @#53398 The whole practical rationale for this is cases like for example a "bare metal" system where your program starts up in a power-on reset interrupt. From there on it calls the C run-time start-up code _never to return_, so no need to waste stack on storing return address etc. Then the C run-tim...
(more)
about 2 years ago
Comment Post #285968 @#53078 The C standard is fuzzy and only says that the pointed-at data should be regarded as an array of objects with "a fundamental alignment requirement" (an alignment less than or equal to the greatest alignment supported by the implementation in all contexts). So the alloc functions may grab more...
(more)
about 2 years ago
Edit Post #285974 Initial revision about 2 years ago
Answer A: noreturn function with non-void return type
Syntax-wise it is a function specifier and may in theory appear everywhere where `inline` (or rather the syntax item function-specifier:) can appear, since the standard doesn't say otherwise. Though of course it would be nonsense to declare `Noreturn` together with a return type and a compiler failin...
(more)
about 2 years ago
Comment Post #285969 Discussion about resource requests specifically: [How does the community feel about resource requests?](https://software.codidact.com/posts/277530)
(more)
about 2 years ago
Comment Post #285911 Also related: [The size of the code format window is much too small.](https://software.codidact.com/posts/278868)
(more)
about 2 years ago
Edit Post #285971 Initial revision about 2 years ago
Answer A: Software recommendations category
At some extent, you can ask about (programming-related) software recommendations if you manage to narrow down the scope to something specific. A question like "which one of compiler x and compiler y currently got the best support for language standard z? I'm mainly interested in features a, b and c."...
(more)
about 2 years ago
Edit Post #285968 Post edited:
about 2 years ago
Edit Post #285968 Post edited:
about 2 years ago
Edit Post #285968 Initial revision about 2 years ago
Answer A: Is it OK to use scanf with a void pointer?
Void pointers are compatible with every other object pointer type and as mentioned in another answer, 7.21.6/10 speaks of the type of the pointed at object, not the type of the pointer. This is consistent with the rules of effective type/pointer aliasing (6.5/6), which have to be applied as well, sin...
(more)
about 2 years ago
Comment Post #285957 @#8196 All of these are artificial examples. The whole point of using forward declaration in the context of opaque types is to block the caller from knowing anything about that type - which as it happens means that they won't know the struct size either. As for dynamically allocating an array of func...
(more)
about 2 years ago
Comment Post #285956 @#8196 And how exactly is it less duplication to increase the references to the `p` identifier from 3 times to 6 times? Imagine if it isn't called `p` but `long_contrived_name_foo`, which happens to have a sibling `long_contrived_name_bar` and if we mix up these identifiers, everything will crash & b...
(more)
about 2 years ago
Comment Post #285956 @#53305 That's an excellent argument actually. The argument in favour of this `sizeof *p` style is that someone would aimlessly change the _type_ of a variable without checking the code using that variable. But what if they change the _identifier_ of that variable instead - again without checking the...
(more)
about 2 years ago
Edit Post #285957 Initial revision about 2 years ago
Answer A: When does it not work to dereference the pointer for sizeof during malloc?
In addition to all the examples I gave in my answer to the linked post, all scenarios where `p` is a pointer to incomplete type fails. Not just the `void` scenario, but also when `p` is a pointer to an array of incomplete type: int (p)[] = malloc(n sizeof p); // will not compile cleanly An...
(more)
about 2 years ago
Comment Post #285956 Actually, after giving this some thought... a compiler must yield a diagnostic message when de-referencing a void pointer _and passing it to `sizeof`_. Both gcc and clang do this in `-pedantic` mode. They are required to do so by constraints 6.5.4.3 regarding the sizeof operator. So yes something is ...
(more)
about 2 years ago
Comment Post #285956 De-referencing void pointers is not allowed as per 6.3.2.2 "The (nonexistent) value of a void expression (an expression that has type void) shall not be used in any way, and implicit or explicit conversions (except to void) shall not be applied to such an expression." Clang seems to fail in issuing a...
(more)
about 2 years ago
Comment Post #285956 `p[i][j]); // Add asterisk to p[i][j]` Shouldn't it be `*p[i][j]`?
(more)
about 2 years ago
Comment Post #285946 `_Nonnull` don't use this. First of all, convention gives that this ought to be the caller's responsibility. Second, if you insist on using such features, the standard already has support for this through `static`. And lately compilers also have added support for it. So if you wish to protect against...
(more)
about 2 years ago
Edit Post #285952 Initial revision about 2 years ago
Answer A: stpecpy(): Design a better string copy function that truncates
- Performance-wise, I'd benchmark this vs `if(memchr(src,'\0',n)==src+n) memcpy(dst, src, n);` because it isn't obvious at least to me if that's faster or slower than your custom function. - Regarding where `end` is pointing, I think that's the right call since it's convenient to have a pointer to t...
(more)
about 2 years ago
Comment Post #285910 @#8196 The equivalent `int (*p)[5]` would have been just as problematic. There's plenty of examples where the style simply doesn't work well.
(more)
about 2 years ago
Comment Post #285899 @#53937 Really? I haven't heard about that and the C committee hates fixing language flaws at the expense of backwards compatibility. Such a radical change would be nice but it also means that all C code out there won't be compatible with C2x.
(more)
about 2 years ago
Comment Post #285899 Expect casting to the expected type is a common way to dodge implicit promotions, so doing so might actually be considered good practice depending on context. For example MISRA-C wouldn't allow this code `unsigned short a,b; ... signed int c = a + b;` but require `c = (signed int)(a + b)`. Though thi...
(more)
about 2 years ago
Comment Post #285908 You could take the live production database and have it copied to a second instance on regular basis, for example at the same time when backups are running. This identical, continuously updated copy of the real database becomes your test one, where you are free to play around. This also allows you...
(more)
about 2 years ago
Edit Post #285912 Initial revision about 2 years ago