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: 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)
over 2 years ago
Answer A: How to properly use malloc?
Should we cast the result of malloc? The cast to the intended type is not necessary in C, since during assignment, the `void` returned by `malloc` can be implicitly converted to any other object pointer and vice versa (as per C17 6.5.16.1). So the cast does add clutter. However, there's nothing wr...
(more)
over 2 years ago
Question A cleanup of "What type of questions can I ask here?"
What type of questions can I ask here? has gotten rather cluttered since we have added/removed a lot of things along the way. In particular, I think it is hard to get an idea of what's on-topic by just taking a glance at it. Proposed changes: 1) Move the text directly below on-topic to a separa...
(more)
over 2 years ago
Answer A: Should we allow UI/UX questions in our community?
I think it should be on-topic with the following distinction: On-topic - Technical questions regarding to UI, including mark-up language syntax, how to set properties in RAD tools, how to use graphic libraries etc. - Algorithm questions for how to draw graphics, including at some extent the math...
(more)
over 2 years ago
Answer A: Why object-oriented instead of class-oriented?
As with anything computer science-related that dates back to the 1960s and 70s, things just happened at a whim. Everything was new and highly experimental back then. Nobody knew how to write or design programs the best way, how to organize them or what coding styles that were most readable. The whole...
(more)
over 2 years ago
Answer A: Are there references in C?
Yes there are references and pass-by-reference in C, though the language has no explicit syntax item called "reference" like C++. In a C context, it is irrelevant that C++ happens to have something called references, which are basically glorified, read-only pointers. The general computer science t...
(more)
over 2 years ago
Question Are there references in C?
When reading posts at programming sites such as this one, I frequently encounter people saying things like: "There is no pass-by-reference in C, everything is passed by value." People claiming such tend to be of the C++ programmer variety and are used to the C++ syntax distinction between poi...
(more)
over 2 years ago
Answer A: Question regarding an error message in my compiler to do with my code on linked list.
To use the identifier `Node` without typing `struct Node`, you must use a `typedef`: typedef struct Node{ // this here is a stuct tag int data; struct Node next; // this has to be struct Node, refers to the above tag }Node; // but from this line and onward we can use Nod...
(more)
over 2 years ago
Question How do I search for "i++"?
I once wrote this post here: Why can't we mix increment operators like i++ with other operators? When using Codidact search looking for that post, I tried to type `i++` in the search but it didn't like that syntax. Then I tried `"i++"` but then the search gave no results. How should I search for t...
(more)
over 2 years ago
Answer A: How to best ask about algorithmic problems
This question was of very poor quality and should have been closed. I closed it but someone disagreed, for reasons unknown. I'm not sure if it's an actual algorithm question or just a request for free code. C strings are very specific to that programming language and I'm not sure if it's even meaning...
(more)
over 2 years ago
Answer A: Community feedback: What type of questions can I ask here?
I propose that we add the following: > Off-topic > - Questions about code golf, programming puzzles and challenges. Please use Code Golf instead.
(more)
over 2 years ago
Answer A: Behavior of Pointer Arithmetic on the Stack
Generally speaking, pointer arithmetic is undefined behavior unless carried out on arrays. This is how the additive operators behave, C17 6.5.6: > For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of a...
(more)
over 2 years ago
Answer A: Why does fopen return NULL?
- The simple explanation would be that you simply don't have write access to the path, which is one possibility. - Another weird phenomenon that may happen is that you are running a very old C compiler and it can't find `fopen` - because you did forget to `#include `. When this happens on mo...
(more)
over 2 years ago
Answer A: What does the greater than 0 indicate in the case of this statement 'if (compare(A[j], A[j+1]) > 0)' ? Thank you.
Generally speaking, comparison callback functions in C are often implemented to return an integer lesser than zero, equal to zero or greater than zero - depending on if the first object is lesser than, equal to or greater than the second object. How it is done in your case, there's no telling sinc...
(more)
over 2 years ago
Answer A: What does the static keyword do in C?
Storage class specifiers `static` is strictly speaking a storage class specifier, which is an attribute given to a variable or a function stating how it is allocated, how it is accessible and how long it will be valid. Other examples of storage class specifiers are `extern` and `register`. It s...
(more)
over 2 years ago
Question What does the static keyword do in C?
What exactly does the `static` keyword do in C? I have seen it used in several diverse contexts: 1) As a variable outside a function: ```c #include static int x = 5; int main (void) { printf("%d\n", x); } ``` 2) As a variable inside a function: ```c void func (void) { s...
(more)
over 2 years ago
Question Questions easily answered by studying a beginner-level book
This scenario is not yet a problem for this site, but we will get there, since it's a huge problem for Stack Overflow: Someone just picks up a well-known programming language for the first time. Then they almost immediately post a question on an online programming forum, which they could have easi...
(more)
over 2 years ago
Answer A: Common string handling pitfalls in C programming
The reader is assumed to understand how arrays and pointers work in C. You cannot understand pointers before you understand arrays, and you cannot understand strings before you understand pointers and arrays both. Decent C books therefore teaches arrays, then pointers, then strings, in that order. ...
(more)
over 2 years ago
Question Common string handling pitfalls in C programming
Preface: This is a self-answered Q&A meant as a C string handling FAQ. It will ask several question at once which isn't ideal, but they are all closely related and I'd rather not fragment the post into several. When reading C programming forums or code written by beginners, there is a number o...
(more)
over 2 years ago
Answer A: Are general questions (hopefully resulting in comprehensive, 'canonical' answers) in scope
Generally these questions are fine, though they should come with specific examples, so that they become clearer and can get narrowed-down. I've done a lot of self-answered Q&A here and the hardest part is often to ask a sensible question. - Overly broad questions like "what is OOP?" isn't likely t...
(more)
over 2 years ago
Answer A: Should we allow questions about installation and configuration of software development tools?
Generally, I would say: On-topic - How to install, configure, trouble-shoot and use tools specifically meant for software development. Compilers, debuggers, IDEs and so on. - Asking questions regarding the above in good faith, as in assuming your problem is related to the specific programmer t...
(more)
over 2 years ago
Answer A: Is this a good fit for Code Reviews, and if so, how to best post it?
400 lines is not that big, it should be fine to post the complete program below the Code Reviews post category. I'd post it as separate code formatted blocks with one block per file indeed. A reviewer can then fairly easily reproduce the project. Plus then you'll get a review on the overall design...
(more)
over 2 years ago
Answer A: Are there practical reasons for designing a method-only class/object?
Many languages support the concept of functors or function objects which are classes only containing a method/member function. Most notably C++ STL was designed around this - whenever you declare a C++ standard container class object, you have the optional argument defining how that container is s...
(more)
over 2 years ago
Answer A: How to do private encapsulation in C?
The concept you are looking for is referred to as opaque type or opaque pointers. This is the proper method to achieve private encapsulation in C and can also be used for inheritance/polymorphism (which I won't address in this answer). It allows multiple object instances of the same class. Opaque ...
(more)
over 2 years ago
Question How to do private encapsulation in C?
I'm using an object-oriented design for my C project and trying to implement classes with private encapsulation. How do I do this? Some things I've tried that are problematic: - Using a struct for my class and placing the struct definition in the header file, then designing the API around this and...
(more)
over 2 years ago
Answer A: What might happen if I ignore warning?
Warnings most often mean "here is a bug which will likely cause your program to crash or misbehave". They do not mean "here's something that you can optionally fix when you can spare the time". See What must a C compiler do when it finds an error? In your specific case, ignoring the warning leads ...
(more)
over 2 years ago
Answer A: How allocated memory is calculated?
The size of the "primitive data types" int, float etc is not defined by the standard. In practice, int is either 16 or 32 bits on all known systems. Because of the unspecified size leading to poor portability of the primitive types, the stdint.h library was introduced back in 1999, containing fixe...
(more)
over 2 years ago
Question Sorting answers by score appears to be broken
https://software.codidact.com/posts/277536/278390?sort=score At the point when I'm posting, the answer by Lundin has +14 score and the answer by dmckee‭ has +11 score. Neither has any down votes. Yet when I sort by score, it doesn't show the answer with highest score first. Clicking on "score"...
(more)
over 2 years ago
Answer A: How to declare variable-length arrays correctly?
C programs are executed from top to bottom. You can't declare a VLA with an uninitialized variable as its size parameter. For the same reason at you can't do this: ```C int x; printf("%d\n",x); scanf("%d",&x); ``` If I type `5` as input to this program, then it doesn't magically go back and...
(more)
almost 3 years ago
Question How to declare variable-length arrays correctly?
This is meant as a FAQ Q&A regarding variable-length arrays (VLA). The two bugs described below are surprisingly common. I'm trying to use the variable-length arrays feature of C99 (and newer) but I'm facing problems with it. - Whenever I write a program like this, I get strange crashes and...
(more)
almost 3 years ago
Answer A: What's the difference between Inheritance and Polymorphism?
> Does Inteheritance actually meant return and Polymorphism meant to print out values? This doesn't make the slightest sense... Probably you should forget all you've heard - don't "watch tutorials", start over with a good book on the subject written by an actual expert. To answer the questions,...
(more)
almost 3 years ago
Answer A: Why does this code that uses a pointer-to-pointer-to-int segfault?
Bugs: - `int range = 0;` should be `int range;` and then call the function like ` ftultimaterange(&range, min, max);`. That's the whole reason the parameter is pointer-to-pointer, so that you can return a malloc:ed pointer through a parameter. - `while (min `length`
(more)
almost 3 years ago
Answer A: BMPL: The language I'll bring to life
First of all, I realize that this is mostly a library you've implemented while learning programming, for the sake of learning, which is great. So I would rather not put a "wet blanket" over your attempts of coding and coming up with libraries, keep on doing that! However, I hope you realize that a...
(more)
almost 3 years ago
Answer A: What compiler options are recommended for beginners learning C?
My recommended beginner setup for gcc-like compilers is: `-std=c11 -pedantic-errors -Wall -Wextra -Werror` Here is an explanation of what these options do: - `-std=c11`. gcc & friends are by default set to include non-standard language extensions. These extensions are known as "GNU C" and ex...
(more)
almost 3 years ago
Question What compiler options are recommended for beginners learning C?
When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed. Then upon viewing their code, I notice that the code should never have "...
(more)
almost 3 years ago
Answer A: constructor in C
The warnings just say that you can't pass a string literal with type `char[]` to a function taking a `struct Book` parameter. The function should be declared as: void initBooktypes (const char title, const char author, int pages); And in the constructor, `aTitle` needs to be `aTitle->title`...
(more)
almost 3 years ago
Answer A: Can we migrate office suite related questions to the Power Users community?
I went ahead and made a proposal on Power User that a separate category for office suites should be made. I suggest that we wait and see where that proposal lands. If a category for these questions is made, we can go ahead and migrate. (Such a category would also soften the "bump blow" that comes...
(more)
about 3 years ago
Answer A: Etiquette for posting comments
Regarding "snark" - it is very hard and subjective to define. Our overall code of conduct says "be nice", but where do you draw the line. On SO, general gruff attitude tends to be treated very differently from moderator to moderator. That's obviously far from ideal. We would have to be smarter abo...
(more)
about 3 years ago
Answer A: Write to same file from multiple threads
Writing to the file on the HD is your massive bottleneck no matter how many threads you throw around. The limit is the physical memory access speed, not processing power. And since it is such a bottleneck, you should have a thread solely focusing on this job, similar to what @dmckee‭ suggested. N...
(more)
about 3 years ago
Answer A: Is strcpy dangerous and what should be used instead?
Summary (TL;DR) - Using `strcpy` directly on non-sanitized user input is bad, otherwise it's fine. - `strncpy` is a dangerous function that should be avoided. Its presence in your source is a much greater danger than buffer overruns. - If portability and backwards-compatibility are no concer...
(more)
about 3 years ago
Question Is strcpy dangerous and what should be used instead?
I heard rumours that the `strcpy` function is dangerous and shouldn't be used. Supposedly it can be exploited to create buffer overflows somehow. And indeed when I compile my C code in the admittedly non-conforming Visual Studio C compiler, it warns me about using `strcpy` among other functions, ...
(more)
about 3 years ago
Question Code formatting of previews
I just noticed that I'm not getting code formatting in the preview window when I write an answer or make an edit. This is very useful to have. Not sure if it's a bug so I'm posting this as a feature request. I'm not getting code formatting when I use language-specific formatting tags: ```c++ t...
(more)
about 3 years ago
Answer A: Warn of implicit cast in a function's arguments with GCC?
You can use `-Wconversion` but you should be aware that it is very prone to false positives. It's a good flag to turn on during code review etc to shake out a few minor issues, but it's not a flag you should leave on permanently. gcc isn't very good at so-called static analysis in the first place....
(more)
about 3 years ago
Answer A: Multiple catches with almost the same code.
There are many things we label as bad when programming, for various reasons. Repeating code is slightly bad. But writing function like-macros is extremely bad. You should not try to replace something slightly bad with something extremely bad. As it turns out, the programmer putting out fire with ...
(more)
about 3 years ago
Answer A: Are code troubleshooting posts allowed?
You are right, the on-topic page is confusing - trouble-shooting and general programming questions should obviously be on-topic! Perhaps we considered it so obvious that it fell between the lines on What type of questions can I ask here? That on-topic page is still kind of in the draft stages. ...
(more)
about 3 years ago
Answer A: Is `uint8_t` always an alias for a character type if it exists?
Yes, it is in practice always a character type and you can safely assume as much, both in terms of (g)lvalue access and in terms of strict pointer aliasing. If not, the compiler would soon render itself completely useless. C and C++ both got the following rule (C17 7.20.1.1/3) > `intNt` ... `u...
(more)
about 3 years ago
Answer A: What is CPU endianness?
This goes back to the various CPU architecture "wars" in the 1970s-1980s between the competitors Intel and Motorola (for example Intel 8086 vs Motorola 68000). For various reasons, CPUs from these two manufacturers ended up with different byte ordering in relation to each other. Byte ordering referri...
(more)
over 3 years ago
Question What is CPU endianness?
I was fooling around with the following C code on my trusty old x86 PC: ```c #include #include int main (void) { uint32t u32 = 0xAABBCCDD; uint8t ptr = (uint8t)&u32; for(sizet i=0; i<sizeof(uint32t); i++) { printf("%.2X", ptr[i]); } } ``` To my surprise, this print...
(more)
over 3 years ago
Answer A: What is do { } while(0) in macros and should we use it?
The sole purpose of the `do { } while(0)` is to write macros that accommodates to all manner of diverse coding styles. It is quite common not to use braces after `if` statements, so this is a common coding style: if(bad) HCF(0xDEADBEEF); else printf("good"); If we only us...
(more)
over 3 years ago
Question What is do { } while(0) in macros and should we use it?
Background I can see the need to use `{ }` when implementing a function-like macro such as this one: #define HCF(code) fprintf(stderr, "halt and catch fire"); exit(code); Because if we use the following calling code bool bad = false; if(bad) HCF(0xDEADBEEF); print...
(more)
over 3 years ago