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
These examples have undefined behavior and unspecified behavior all at once! Operator precedence has nothing to do with the order of execution, see What is the difference between operator precedenc...
When posting a lot of code on the site, the "code format window" is much too small: 1 I'm talking about this thing 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The scroll bar appears after...
I was fooling around with the following C code on my trusty old x86 PC: #include <stdint.h> #include <stdio.h> int main (void) { uint32_t u32 = 0xAABBCCDD; uint8_t* ptr = (u...
Yes, the second line invokes undefined behavior. First of all, according to C17 6.5.2.1 regarding array subscripting, an expression E1[E2] is just "syntactic sugar" for *((E1)+(E2))). So what appli...
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: int x; printf("%d\n",x); scanf...
SIGSEGV is defined in the C header signal.h. To generate the signal, it should be sufficient to just do raise(SIGSEGV);. As far as I know, this is well-defined behavior.
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 poin...
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 su...
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 l...
When doing something simple such as this int a=1; int b=2; int c=3; printf("%d\n", a + b * c); then I was told that operator precedence guarantees that the code is equivalent to a + (b * c)...
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 co...
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 muc...
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 init_Book_types (const char* tit...
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...
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 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...
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 newe...
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 tutoria...
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 at...
It is true that MISRA-C has a heavy focus on embedded system, though it has become somewhat more generic over time. The MISRA guidelines have been changed and improved several times over the years ...
When discussing best or safest C programming practices with various C gurus on the Internet, the "MISRA-C guidelines for the use of C language in critical systems" often pops up as a source. This ...
Google Sheets isn't a company name, it's a product name. A tag called google-sheets is perfectly fine. Google doesn't market this product as "Sheets", they market it as "Google Sheets". What is not...
I'm experimenting with different operators and have a hard time understanding the outcome of certain expressions. I try to combine the ++ operators with other operators such as assignment in the sa...
C23 introduces the digit separator ' which can be placed anywhere inside an integer constant for the purpose of clarity and self-documenting code. These are otherwise ignored by the compiler when d...
In older C and C++ standards, the auto keyword simply meant automatic storage duration. As in the compiler automatically handles where the variable is stored, typically on the stack or in a registe...