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 klutt‭

Type On... Excerpt Status Date
Edit Post #285899 Post edited:
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Comment Post #285957 The first example with pointer to array with unknown size was the most confusing at first. But I guess it's about the same thing as the struct/union example. If you want to allocate an array of arrays, you do want to know the size of the array. And if you don't something is weird. And also, would ...
(more)
about 2 years ago
Comment Post #285957 Nice answer! Some questions here. Regarding allocation of forward declared structs/unions. Spontaneously, I think this looks like a really strong code smell. Am I right? It just feels like something is very wrong if you are about to allocate memory for a struct array before knowing the size of th...
(more)
about 2 years ago
Comment Post #285956 @#8176 I'm 100% confident that you understand what I'm trying to illustrate. If you think that "code duplication" isn't a good phrase to use, please suggest another one.
(more)
about 2 years ago
Edit Post #285956 Post edited:
about 2 years ago
Comment Post #285956 The duplication comes if you have this: int *p; p = malloc(10 * sizeof(int)); free(p); p = malloc(10 * sizeof(int)); free(p); p = malloc(10 * sizeof(int)); Changing `p` to `long*` would require three extra changes.
(more)
about 2 years ago
Edit Post #285956 Post edited:
about 2 years ago
Comment Post #285956 Indeed. Fixed it. Thanks.
(more)
about 2 years ago
Edit Post #285956 Post edited:
about 2 years ago
Comment Post #285956 I'm not quite sure what you're saying here. Are you saying that something is wrong?
(more)
about 2 years ago
Edit Post #285956 Post edited:
about 2 years ago
Edit Post #285956 Post edited:
about 2 years ago
Edit Post #285956 Initial revision about 2 years ago
Question When does it not work to dereference the pointer for sizeof during malloc?
Background This is kind of a subquestion to How to properly use malloc? When allocating, there are basically two common ways of using the `sizeof` operator: int p; p = malloc(n sizeof p); // Method 1: Dereference the pointer p = malloc(n sizeof(int)); // Method 2: Explicitl...
(more)
about 2 years ago
Comment Post #285910 @#8176 What's problematic with that one? I do indeed expect `sizeof *p` to be 20 bytes with 32-bit int, which it also is. (I checked because you made me believe it would be something else :) ) I'd also like to add that it's a pretty unrealistic example. You declare a local pointer in the argument ...
(more)
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Comment Post #285910 I would argue that `void failloc (int n, int p[5][5])` isn't a very good counterexample. Using arrays as parameters can indeed be very confusing. And regarding your pointer to pointer example, I'd say that it is very consistent. You just do `p[i] = malloc(y * sizeof *p[i])`
(more)
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Comment Post #285899 @#8176in "Depending on the context" is my exact point. You don't throw them in everywhere just for the sake of it.
(more)
about 2 years ago
Comment Post #285908 About step 3. I would definitely not have that as an automatic step.
(more)
about 2 years ago
Comment Post #285902 @#53280 Actually, we ended up using httpinterceptors for this purpose instead. It was quite clean to implement. However, we also kept your suggestion to make sure that logging out occurs if the user is inactive.
(more)
about 2 years ago
Comment Post #285899 When they standardized C to C89, they took various ideas from different implementations where some had extensions like the void pointer. The important thing wasn't exactly when and where void pointers became a concept, but instead just the fact that void pointers are very old and arguments based on t...
(more)
about 2 years ago
Comment Post #285899 I updated to a better example
(more)
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Edit Post #285811 Post edited:
about 2 years ago
Edit Post #285811 Post edited:
about 2 years ago
Comment Post #285899 I removed that part. I was remembering completely wrong.
(more)
about 2 years ago
Comment Post #285902 I completely understand your skepticism, but this is not the typical office environment. I also hate such features, but in this case it's a security issue that's not negotiable. In the case that someone get interrupted by another task it's actually imperative that this automatic logoff works. Howe...
(more)
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Comment Post #285902 Thanks, I'll look into it. However, I was really hoping to not have to redesign everything just to fix this bug. Task switching is not a thing in this environment. :)
(more)
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Edit Post #285899 Post edited:
about 2 years ago
Edit Post #285899 Initial revision about 2 years ago
Answer A: How to properly use malloc?
TL;DR You should use int p = malloc(n sizeof p); for two reasons 1. The cast `(int)` is not necessary, which means it's clutter. 2. Using `sizeof p` instead of `sizeof(int)` removes code duplication. But remember to check if allocation succeeded before using the memory. It's don...
(more)
about 2 years ago
Edit Post #285898 Initial revision about 2 years ago
Question How to properly use malloc?
I have seen this construct quite a lot: int p = (int) malloc(n sizeof(int)); Is this how it should be? What is the proper way to use `malloc`? I have also seen this: int p = malloc(n sizeof p); Which one is preferable?
(more)
about 2 years ago
Edit Post #285897 Post edited:
about 2 years ago
Edit Post #285897 Initial revision about 2 years ago
Answer A: Are there references in C?
This question most often comes up in relation to C++. That language has something that is called reference in the standard. They work like pointers, with a few differences. 1. They have to be initialized, because (2) 2. They cannot be reassigned. They will always point to the same object. 3. Th...
(more)
about 2 years ago
Edit Post #285896 Initial revision about 2 years ago
Question Are static pointers implicitly initialized to NULL?
Consider this code: ``` #include int main(void) { static void ptr; if(ptr == NULL) puts("It's NULL!"); } ``` I wonder if this is guaranteed to print "It's NULL!" I know that 1) Initializing or assigning a pointer to `0` is equivalent to initializing or assigning it to `NU...
(more)
about 2 years ago
Edit Post #285894 Initial revision about 2 years ago
Question Suggestions for improving the UI regarding comments
See this picture Expanded comment thread How do you answer in that thread? Hmm, there are two buttons. One says "show more". I click on that and the thread collapse. Is that "more"? Collapsed thread Ok, so I click on the thread again to get back to the first picture. There's one more butt...
(more)
about 2 years ago
Comment Post #285875 TBH, I think the original phrasing is pretty ok. The problem is how it would have been interpreted on SO. Because there, "too opinionated" means "not 100% objective".
(more)
about 2 years ago
Comment Post #285883 Updated the question
(more)
about 2 years ago
Edit Post #285883 Post edited:
about 2 years ago
Edit Post #285883 Post edited:
about 2 years ago
Edit Post #285811 Post edited:
about 2 years ago