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.
Posts by Lundin
See Software recommendations category. Referring to my own answer there, I think these questions should only be on-topic in case the OP manages to narrow down the scope sufficiently. In case the qu...
memcpy(&y.t, &x, sizeof(x)); is a bit fishy since it would have made more sense to copy into &y or &y.s. None of this is necessarily UB however. Regarding strict aliasing, it doesn...
p is assigned a value and then it becomes indeterminate when the pointed at object has reached the end of its lifetime (C17 6.2.4). Pointers may have trap representations (C17 6.2.6.1/5) and in ca...
Regarding undefined behavior/uninitialized variables of automatic storage duration First of all there's some misconceptions here. if (x == 0) is UB only because x was declared as a local variable...
After some more experience from this bot over a couple of months, I would say that we should ban it simply because: The answers it gives are often wrong. ChatGPT has been hyped up ridiculously. I...
Since I don't think the C standard says anything explicitly about cases like this, it is probably undefined behavior, under the "not mentioned in the standard" variety. If something isn't mentioned...
Assuming that there are no alignment problems between the two pointer types (impl-defined), the code is otherwise well-defined. As per the quoted 6.3.2.3 C allows pretty much any form of wild and c...
The ambition of this site was always to give more room for subjective and big picture questions compared with Someplace Else. However, I believe programming language design falls under the topic of...
As someone who spent a lot of time trying to get this to work on Stack Overflow, I would advise against it. Some background story of my merry adventures with book lists: The story starts around...
For what it's worth, I have some 20 years of experience designing embedded C systems, with large and small code bases both. Code design is some of the hardest things to do, since books about object...
It depends. This boils down to whether or not the expression cast to void contains any side effects, such as accessing a volatile-qualified object or modifying any object. C17 6.3.2.2: If an ex...
Yes it is fine and probably encouraged even. I have written several self-answered Q&A here and they were mostly well-received. They aren't all that easy to write though, especially getting the ...
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 stan...
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*). char* foo (const char* str) { r...
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 whe...
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 explic...
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 po...
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 ...
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 ra...
C++ doesn't have error codes/exit codes other than return 0; / EXIT_SUCCESS / EXIT_FAILURE. The code you are getting is from the OS when your program crashes from a run-time error. -1073740940 is ...
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 ...
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 ...
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 con...
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 ...
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...