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 #292978 |
It is particularly important to discuss matters of program design and coding style with beginners, or otherwise they pick up bad habits from the start and carry those with them through their career. Therefore, giving everyone a forum to ask about such matters is important. (more) |
— | 2 days ago |
Comment | Post #292978 |
This is a bit of a rant so I kept it out of the answer:
Some sites like SO have very strange misconceptions rooted into the site culture, such as the misconception that program design and coding style questions don't belong on a programming site. That's plain silly IMO - that's not how software en... (more) |
— | 2 days ago |
Edit | Post #292978 | Initial revision | — | 2 days ago |
Answer | — |
A: Comparing our site scope to Stack Overflow The main difference between Stack Exchange and Codidact is that SE loves to spawn off hundreds of sites with lots of overlapping scopes, whereas Codiact has the category system, which means that contents like for example AI and GenAI could exist on the same site. The general idea about software.c... (more) |
— | 2 days ago |
Edit | Post #292976 | Initial revision | — | 3 days ago |
Answer | — |
A: Understanding "logical OR" and "logical AND" in programming languages They aren't actually that different from natural language. But more verbose. Given some generic pseudo code looking like one of the C family languages: ``` if( !egg.boiled || !egg.peeled ) { donoteat(egg); } ``` Then this is to be translated as: "If the egg is not boiled or the egg is... (more) |
— | 3 days ago |
Edit | Post #284849 |
Post edited: |
— | 4 days ago |
Edit | Post #292934 | Question closed | — | 9 days ago |
Comment | Post #292934 |
We'll need far more details than that. What libs or RAD tool were used, if any? How do you take keyboard input? If it's a raw Winapi program then please post relevant parts of the code by editing the question. (more) |
— | 9 days ago |
Edit | Post #289414 |
Post edited: |
— | 10 days ago |
Comment | Post #292695 |
@#53937 Once some behavior makes it into the Unix/POSIX libs, it tends to stay the same (for good or bad). But I would imagine that you would find oddities if you'd go on a tour and inspect all embedded systems compilers out there - most were designed for targets where heap allocation is senseless. S... (more) |
— | about 1 month ago |
Edit | Post #292819 | Initial revision | — | about 1 month ago |
Answer | — |
A: How do you implement polymorphism in C? First of all please note that polymorphism in C is clunky. It won't be pretty. We don't have `this` pointers, we don't have RAII, we don't have automatic constructors/destructors. Just accept that it the code won't look as pretty as in languages that have all of these features. Second, we really o... (more) |
— | about 1 month ago |
Edit | Post #292818 | Initial revision | — | about 1 month ago |
Question | — |
How do you implement polymorphism in C? The topic of how to implement polymorphism in C tends to pop up now and then. Many programmers are used to OO design from higher level languages and supposedly OO is a "language-agnostic" way of proper program design no matter language. So how to do it in C? A design pattern I've often seen is to ... (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#82304 System APIs have no benefits from providing a scenario where the program may potentially be running off into the woods. They are non-portable, whereas the C standard libs seek to be portable and therefore have vague wording and poorly-defined behavior - sometimes where it is justified, someti... (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 The general approach for readability could be to add an abstraction layer on top of malloc to hide away all the ugly gunk. Or the other way around, strip away malloc and go straight for the system APIs which will be better defined than the C standard libs - at the expense of non-portable code... (more) |
— | about 1 month ago |
Comment | Post #292695 |
...now we could of course always over-allocate malloc with one garbage byte. `malloc(n+1)` but the program only uses `n` bytes. That's 100% portable. (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 As I said in the initial comment, it is probably naive to think `malloc(0)` results in less branches, because there will likely be a special case inside the malloc implementation instead, meaning that a rare branch gets hit. Also the implementation of heap allocation in itself is usually huge... (more) |
— | about 1 month ago |
Comment | Post #292695 |
And well seriously, who thinks `while((*indirect) != entry) indirect = &(*indirect)->next;` is good-looking code? The first parenthesis is superfluous. `&(*indirect)->next;` is obfuscating posing and _here_ an extra parenthesis could perhaps have been motivated: `&((*indirect)->next)`. But the main p... (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 As for Linus Torvalds he's probably as far from a C style authority as you can possible get. Anyone who is disagreeing ought to read the Linux kernel source. I was a fan of Linux until I read the that... afterwards I started to wonder if I need to keep a 10 meter distance to all Linux compute... (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 Obviously you can write that code in any number of ways. `ptr = (size ? malloc(size) : NULL);` for example though I personally think that's less readable. Error handling always comes with overhead - it's a fact. The most elegant code out there is usually not very rugged. (more) |
— | about 1 month ago |
Comment | Post #292748 |
@#53937 C is still flawed. There's the definition of a _null pointer constant_ in C, which is clear. And then there's an ambiguous part regarding the `NULL` macro saying "...NULL which expands to an implementation-defined null pointer constant;". I think the intention was to say it is implementation-... (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 Sounds like premature optimization, `if(size>0) ptr=malloc(size); else ptr=NULL;` is hardly some massive overhead. You can still have your for loop after that and then pass the pointer to free when done. (more) |
— | about 1 month ago |
Comment | Post #292695 |
@#53937 I'd say that _code bases_ relying on malloc(0) are dying platforms. The appropriate way to write programs is to initialize the pointer to NULL, only allocate when there is something to allocate, and upon deallocation pass the pointer along to free() no matter if malloc was ever called or not.... (more) |
— | about 2 months ago |
Comment | Post #292695 |
Rather, nobody knows what exactly it is, because the changes to the standard were of such poor quality that it's all over the place... (more) |
— | about 2 months ago |
Edit | Post #292695 | Initial revision | — | about 2 months ago |
Answer | — |
A: Which platforms return a non-null pointer on malloc(0) It is trivial enough to test: ```c #include #include #include #define KNOWNGARBAGE ((int)0u) int main (void) { int ptr = KNOWNGARBAGE; ptr = malloc(0); int errnochanged = errno; if(ptr == NULL) puts("Returned NULL."); else if(ptr == KNOWNGARBAGE) puts("Didn'... (more) |
— | about 2 months ago |
Edit | Post #291960 |
Post edited: |
— | 2 months ago |
Edit | Post #292618 |
Post edited: |
— | 2 months ago |
Edit | Post #292618 | Initial revision | — | 2 months ago |
Answer | — |
A: I created a tag, now it need edit. Streams is an universal concept not specific to any particular language. It originates from ancient Unix, most famously the stdout and stdin streams. And so they exist in pretty much any "C family" programming language and probably in a lot of other languages as well. Therefore `stream` is not a usef... (more) |
— | 2 months ago |
Comment | Post #292529 |
This isn't really in the domain of the compiler but something called static code analysis. Compilers may do that at some extent as a bonus, but it is not its job. As for clang specifically I believe it comes with a static analyzer built-in which you can invoke with `clang --analyze`. I haven't really... (more) |
— | 2 months ago |
Comment | Post #292371 |
`_X` is an identifier reserved for the library, so for whatever the reason, the compiler doesn't think you are compiling libraries but application code. I suppose this can happen if you mix different library implementations together. There are for example different flavours of Mingw64 CRT: the older ... (more) |
— | 3 months ago |
Edit | Post #292264 |
Post edited: |
— | 3 months ago |
Edit | Post #292264 |
Post edited: |
— | 3 months ago |
Edit | Post #292264 | Initial revision | — | 3 months ago |
Answer | — |
A: New elementsof() operator I don't really see what good `elementsof` would do since `sizeof(arr)/sizeof(arr)` is pretty idiomatic C and problem-free given that you know what you are doing, as is the case with most C code. IMO the C committee should be focusing on fixing known problems and weeding out poorly-defined behavio... (more) |
— | 3 months ago |
Comment | Post #291982 |
@#53937 I don't see why `auto ap_ = ap;` is any better than `typeof(ap) ap_ = ap;` though. And in either case you risk getting parameters that have gone through implicit conversion by accident, so this would be better off as a function. (more) |
— | 3 months ago |
Edit | Post #291982 |
Post edited: |
— | 4 months ago |
Edit | Post #291982 |
Post edited: |
— | 4 months ago |
Comment | Post #291981 |
@#53549 It doesn't really assume anything, it just asks why someone would consider it dangerous. This was actually the beginning of a self-answered Q&A and I had considered to show plenty of examples in the answer part.
It would indeed to a very good question to ask for the committee(s) intent or ... (more) |
— | 4 months ago |
Edit | Post #291982 | Initial revision | — | 4 months ago |
Answer | — |
A: Why is the new auto keyword from C++11 or C23 dangerous? The `auto` feature was indeed mainly meant to solve long cumbersome template container declarations in C++. But when introduced to C23 - where there are no templates let alone template containers - it just ends up as a solution without any problem that it solves. `auto` can create new problems ju... (more) |
— | 4 months ago |
Edit | Post #291981 | Initial revision | — | 4 months ago |
Question | — |
Why is the new auto keyword from C++11 or C23 dangerous? 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 register. And it was a pretty useless keyword since it can only be used at local scope, where all variables d... (more) |
— | 4 months ago |
Edit | Post #291960 |
Post edited: |
— | 4 months ago |
Edit | Post #291960 | Initial revision | — | 4 months ago |
Answer | — |
A: Closing self-answered question due to not being clear enough A question should be closed when it cannot be meaningfully answered by someone who knows the topic. Which might indeed mean that the one(s) casting the close vote(s) would need domain knowledge. That is, it would be impossible answering it without speculating or coming up with opinions. Or the q... (more) |
— | 4 months ago |
Comment | Post #291898 |
This question is getting discussed at meta: [Closing self-answered question due to not being clear enough](https://software.codidact.com/posts/291929). (more) |
— | 4 months ago |