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 |
---|---|---|---|---|
Comment | Post #288020 |
@#53937 The compiler isn't allowed to insert side effects in a program which isn't there in the source. `free()` has no side effects related to the passed pointer variable, only related to what it points at. It's kind of a C design flaw that `free()` doesn't take a pointer to pointer as parameter. Th... (more) |
— | about 2 years ago |
Edit | Post #288020 | Initial revision | — | about 2 years 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 2 years ago |
Comment | Post #287917 |
@#53937 Only in case pointers have trap representations. Although... in case someone is curious, because of this very example, I managed to kill the clang 15 compiler's conformance in horrible ways. [clang 15 miscompiles code accessing indeterminate values](https://stackoverflow.com/questions/7553369... (more) |
— | over 2 years ago |
Comment | Post #287917 |
Btw how `memcmp` is implemented internally isn't relevant since that implementation in itself need not be done in C or be conforming C - it is a standard library function. For example it could be implemented in assembler. (more) |
— | over 2 years ago |
Comment | Post #287917 |
@#53937 Yes, from C17 6.2.4: "The value of a pointer becomes indeterminate when the object it points to (or just past) reaches the end of its lifetime." In case of allocated storage, this happens when you call `free()`. For example `int* ptr = original; free(original); if(ptr == original)` is not _r... (more) |
— | over 2 years ago |
Edit | Post #287917 |
Post edited: |
— | over 2 years ago |
Edit | Post #287917 |
Post edited: |
— | over 2 years ago |
Comment | Post #287908 |
The crux here is that an optimizing compiler can completely omit the `memcmp` call in the first place. Since the value of the passed object holds an indeterminate value, the compiler is free to replace the whole `memcmp` call with anything like `1` or `0`. It doesn't actually have to execute the func... (more) |
— | over 2 years ago |
Edit | Post #287917 | Initial revision | — | over 2 years 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) |
— | over 2 years ago |
Comment | Post #287842 |
In case of embedded systems: it goes like "do not needlessly connect it to the Internet in the first place". https://www.wired.com/2015/07/hackers-remotely-kill-jeep-highway/ (more) |
— | over 2 years ago |
Edit | Post #287827 | Initial revision | — | over 2 years 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 2 years ago |
Edit | Post #287123 |
Post edited: |
— | over 2 years ago |
Comment | Post #287760 |
@#53937 No that's really the same thing. Structs and arrays mostly follow the same rules in this case (being "aggregates" as far as the effective type rules are concerned). (more) |
— | over 2 years ago |
Edit | Post #287760 | Initial revision | — | over 2 years 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 2 years ago |
Edit | Post #287748 |
Post edited: Typo |
— | over 2 years ago |
Edit | Post #287750 | Initial revision | — | over 2 years 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 2 years ago |
Comment | Post #287607 |
Are Java and C# `interface` common enough to justify using the same tag? Otherwise maybe two tags java-interface and C#-interface would solve the problem. I see no purpose of the tag outside these specific language keywords. (more) |
— | over 2 years ago |
Comment | Post #285727 |
I'd say that the "three pillars" are private encapsulation, autonomous objects and inheritance. Autonomous objects meaning that each object just does it's own designated task and doesn't meddle with other unrelated things - it has _loose coupling_, as few dependencies on other things in the program a... (more) |
— | over 2 years ago |
Comment | Post #287561 |
Just ask the same question here. What answer you got elsewhere and from whom is irrelevant. (more) |
— | over 2 years ago |
Edit | Post #287504 | Initial revision | — | over 2 years 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 2 years ago |
Comment | Post #287454 |
Great job everyone who was involved in finally fixing this! (more) |
— | over 2 years ago |
Comment | Post #287301 |
The problem with "non-authoritative" recommendations is that they become completely subjective. If some random person with random experience likes a certain book, then that doesn't tell us anything more than a random subjective review on Amazon - it all turns low quality and unlikely to be of actual ... (more) |
— | over 2 years ago |
Edit | Post #287123 |
Post edited: |
— | over 2 years ago |
Comment | Post #287137 |
A quality list goes beyond "I have read it and it was good" though, because everyone can read a book and share an opinion of it. You can then get a recommendation about how easy to read and pedagogic the books was (similar to Amazon reviews perhaps). But not a measurement of technical correctness. So... (more) |
— | over 2 years ago |
Edit | Post #287123 | Initial revision | — | over 2 years 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 2 years ago |
Comment | Post #287122 |
One of the most important things I was taught in physics classes back at school was to _always_ convert each operand to the basic SI unit before using it in calculations. That is, always convert km to m. Always convert hours/minutes to seconds. And so on. This for manual calculations - programming is... (more) |
— | over 2 years ago |
Edit | Post #287079 |
Post edited: |
— | over 2 years ago |
Edit | Post #287079 |
Post edited: |
— | over 2 years ago |
Edit | Post #287079 |
Post edited: |
— | over 2 years ago |
Edit | Post #287079 |
Post edited: |
— | over 2 years ago |
Edit | Post #287079 | Initial revision | — | over 2 years 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 2 years ago |
Comment | Post #286979 |
The volatile part doesn't make it UB because of the lvalue access alone, but because of the special rule in 6.3.2.1 which has nothing to do with the value of the variable or traps, but code generation. (more) |
— | over 2 years ago |
Comment | Post #286975 |
@#53398 For the most part it _is_ fine to use such a variable, as in it won't cause you program to crash and burn (not undefined behavior), but it will not produce anything meaningful or deterministic either (it is unspecified behavior). With the exception of trap representations, which are mostly ir... (more) |
— | over 2 years ago |
Edit | Post #286987 |
Post edited: |
— | over 2 years ago |
Comment | Post #286979 |
"we can even read an uninitialized variable with unspecified value safely" This is an over-simplification. Reading a local variable (automatic storage) which was not initialized and never had its address taken (could have been declared with `register` storage class) is explicitly UB as per C17 6.3.2.... (more) |
— | over 2 years ago |
Edit | Post #286987 | Initial revision | — | over 2 years 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 2 years ago |
Edit | Post #286947 | Initial revision | — | almost 3 years 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) |
— | almost 3 years ago |
Edit | Post #283890 |
Post edited: |
— | almost 3 years ago |
Comment | Post #286813 |
I assume you meant to write data-presentation but it is missing from the question. (more) |
— | almost 3 years ago |
Edit | Post #286870 | Initial revision | — | almost 3 years ago |