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
Answer A: Can I access an array element from a pointer to an object contiguous with but outside the array?
The problem with undefined behavior due to array out of bounds happens whenever we use pointer arithmetic, which is only defined to work within the bounds of an array. Where plain variables, "scalars", are defined to behave just the same as arrays of 1 item, as far as pointer arithmetic is concerned....
(more)
about 1 month ago
Answer A: Pattern / architecture for interfacing with components in C
Code review part: Design (important!) - Global variables/external linkage are to be avoided (Why is global evil?). - You don't actually have private encapsulation in this code since the internals of the struct are exposed to the caller. There are better ways to design this with "opaque types" an...
(more)
about 1 month ago
Answer A: Why is global evil?
The basics of good vs bad program design All programs are divided in classes. (Or modules/abstract data types/interfaces etc - a rose by any other name.) Each class should only be concerned with its own designated task and not with unrelated parts of the program. Similarly, each class is aut...
(more)
about 1 month ago
Answer A: How can I manage multiple consecutive strings in a buffer (and add more later)?
When looking at this, we might pretty soon note that storing strings in the same buffer by using null terminators as separator is quite clunky. It blocks us from using handy functions like `strtok`, `bsearch` or `qsort`. And there's no obvious way to tell where all of it ends. To know where it ends, ...
(more)
about 2 months ago
Answer A: Is software system design on topic here?
Software design in itself has always been on-topic, as per https://software.codidact.com/help/on-topic. As for system design for a given purpose, I think it is fine within reason. Contrary to popular belief, a certain degree of domain expertise or at least insight is always necessary when writing...
(more)
about 2 months ago
Answer A: Are there technical reasons to pick one struct coding style over the other?
Arguments in favour of "struct tag style": - Less namespace clutter. C has a peculiar name space system where all identifiers belong to one of: labels, tags, members, ordinary. Struct tag style only occupies a name in the tag name space. Meaning that struct tags will not collide with e...
(more)
3 months ago
Question Are there technical reasons to pick one struct coding style over the other?
C offers two different styles when it comes to structs (and union/enum too). Either declare them using a struct tag only ("struct tag style"): struct mytype { ... }; struct mytype x; Or by using a `typedef`, where the tag is optional ("typedef style"): typedef struct opt...
(more)
3 months ago
Answer A: Trie Implementation, Graph Visualization and Auto-Completion in C
General/program design: - I would have expected a public header file with the API for the whole thing, rather than having some main() test case calling `static` functions from the same file. Sure, this program is small, but having everything in a single file makes things less maintainable. - A ...
(more)
3 months ago
Question Are "strong passwords" at all meaningful?
Whenever registering to diverse sites on the net, you are often forced to enter a so called "strong password", which would ideally contain both upper case letters, lower case letters, digits, and some other character like punctuation. As hard to remember as possible. What I don't understand from a...
(more)
4 months ago
Answer A: When should I parenthesize macro arguments in C?
Simply put: parenthesis are used whenever we suspect that there may be operator precedence issues. - Either because the user passed an expression containing several operands and operators to the macro. To deal with this we need to surround the use of each macro parameter with parenthesis. ...
(more)
6 months ago
Answer A: What is the meaning of "short circuit" operators?
It's an unfortunate analogy. Apart from being confusing, it does indeed assume some basic electronics knowledge. In electronics a short circuit (or the common jargon "a short") does not necessarily refer to a catastrophic event like cables burning up - it just means that you connect two signals/condu...
(more)
7 months ago
Question What is the meaning of "short circuit" operators?
When reading about various operators used by programming languages, the term "short circuit behavior" is often used. For example in this C code: int a = 0; a && b++ Someone explained that `b++` is never executed because the logical AND operator "short circuits". What do they even mean ...
(more)
7 months ago
Answer A: How can we grow this community?
Search engine optimization? I thought this goes without saying, but apparently we aren't doing too well there for some reason. The other day I was having a discussion with someone at SO regarding how hard it was to find specific information about anything on SO, even when using Google for the ...
(more)
8 months ago
Answer A: Handling common wrong approaches and misguided motivations for basic technique questions
I think this is important to consider because it doesn't only concern questions about bad practices or XY questions, but also if we should allow questions with artificial requirements or questions about code obfuscation. Currently we have no rule for/against any of this. As for if we should ca...
(more)
8 months ago
Answer A: Should self-answered Q&A use separate answers for different techniques/approaches (even if there's a caveat that applies overall)?
> the answer is incredibly long It really isn't - though it might look that way because of the extensive use of large font headlines. I think it is a good answer - there's no problem in discussing multiple ways of doing something, addressing every angle. That's good engineering, rather. > Would...
(more)
8 months ago
Answer A: What categories could we benefit from having?
Categories should be used when the posting rules for certain types of question differ. For example a debugging question posted below Q&A should have a minimal, relevant example. Whereas a code review question should have the complete code as-is, without modification. This merits different categories,...
(more)
8 months ago
Answer A: Why does calloc accept 2 arguments, and with what arguments should one call it?
It has 2 parameters for weird historical reasons that nobody seems to know the rationale for any longer. Like most functions in the C standard library, the function API was not well-designed. Keep in mind that many of these functions were designed in the 1960s(!) and early 1970s, some 20 years before...
(more)
9 months ago
Question Tag creation/deletion criteria for Software Development?
Ok so we have fairly lax tagging rules here, as do most Codidact sites. Recently the Electrical Engineering community has started a clean-up of strange and off-topic tags. I wrote this over there: Tag creation/deletion criteria. Those who have a background at SO might recognize the huge system pr...
(more)
9 months ago
Answer A: What is C23 and why should I care?
C23 will be a major revision, certainly the biggest one since C99. It contains lots of changes and new features, both big and small. The linked draft in the question contains a complete list of changes, but it might be a bit overwhelming to read unless you are a "C nerd" and if you aren't used at rea...
(more)
9 months ago
Question What is C23 and why should I care?
The C language has gone through many iterations and the latest one not yet released is informally called "C23", supposedly because they hoped to release it in 2023. The latest draft version N3096 is available for free from the ISO C working group. The previous standard C17 (ISO 9899:2018) didn't r...
(more)
9 months ago
Answer A: Terms for types of functions with respect to side effects
I don't think there are any formal names for the various versions you list. First of all, please note that output in a programming context most often refers to printing something on a screen or to a file, or updating graphics. "Function output" is not a common programming term - almost every lang...
(more)
9 months ago
Answer A: On self-answered questions, is it inappropriate to mark my own answer "Works for me" immediately?
On the contrary, I think that it is appropriate and recommended practice. That way you (the poster of the question) can pick your own answer as the "official" one, since these post often (ought to) take a lot of time to write. Although others are obviously also welcome to post other answers even ...
(more)
9 months ago
Answer A: To transfer, or not to, that is the question: whether 'tis nobler to let it stay or to take arms against Stack Overflow's dominance of FAQ canonicals
I would recommend to post it anew here as a self-answered Q&A and update it if needed. You can use the "works for me" reaction to label your own answer the "official" one. As an example of how this can be done, I once wrote this answer on SO. It needed some tweaks and updates, more sources added e...
(more)
10 months ago
Answer A: Should posting on Meta affect reputation?
Codidact has already managed somewhat to separate domain knowledge from moderator suitability. So far so good, but reputation is also a measurement of activity. It might make sense that being active on meta should be rewarded somehow, just as being active on the main site is rewarded over time. ...
(more)
11 months ago
Answer A: How are software recommendations handled?
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 question contains some sort of use-case/usage scenario and important requirements, it should be OK - other...
(more)
11 months ago
Answer A: Storing more bytes than a union member has, but less than the union size, with memcpy(3)
`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't really matter. If you allocate with a `malloc`-like function then the data has no declared type and effective...
(more)
11 months ago
Answer A: Can freed pointers undergo lvalue conversion?
`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 case the indeterminate value matches a trap representation, the assignment `q = p;` invokes undefined...
(more)
about 1 year ago
Answer A: memcmp(3) memory containing invalid values
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 (automatic storage) without having its address taken - "could have been declared as `register`"...
(more)
about 1 year ago
Answer A: Should we allow answers generated by ChatGPT?
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. It is not that good, it is not that smart, it cannot be trusted to give correct answers to complex to...
(more)
over 1 year ago
Answer A: Is partial allocation of an object Undefined Behavior?
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, it is per definition undefined and not well-defined. The closest thing might be the somewhat unclea...
(more)
over 1 year ago
Answer A: Strict aliasing rules and function boundaries
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 crazy pointer conversions by means of a cast, as long as you don't actually de-reference the pointer thro...
(more)
over 1 year ago
Answer A: Are questions about language design on-topic?
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 general computer science. It doesn't match anything in the current on-topic list. General computing...
(more)
over 1 year ago
Answer A: Should asking about book recommendations directly connected to software development be on-topic?
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 here: Delete the list of random books? Back in 2015 I stumbled upon a list of random books not n...
(more)
over 1 year ago
Answer A: C naming convention, module trigrams?
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 orientation (OO) etc only gets you so far - you have to learn what works out of experience. Generall...
(more)
over 1 year ago
Answer A: Cast uninitialized variable to (void)
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 expression of any other type is evaluated as a void expression, its value or designator is discar...
(more)
over 1 year ago
Answer A: Asking and answering FAQ style questions
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 question right and meaningful, so that people looking for that same problem can find it - or at least so tha...
(more)
over 1 year ago
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)
over 1 year 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 2 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 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
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
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
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
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
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
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
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
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
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
Answer A: Are static pointers implicitly initialized to NULL?
Yes, it is guaranteed to evaluate to true. All variables with static storage duration are set to zero in case of arithmetic types or set to null in case they are pointers. The relevant part is C17 6.7.9/10: > If an object that has automatic storage duration is not initialized explicitly, its value...
(more)
about 2 years ago