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: |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 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) |
— | almost 3 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) |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285956 |
Post edited: |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285956 |
Post edited: |
— | almost 3 years ago |
Comment | Post #285956 |
Indeed. Fixed it. Thanks. (more) |
— | almost 3 years ago |
Edit | Post #285956 |
Post edited: |
— | almost 3 years ago |
Comment | Post #285956 |
I'm not quite sure what you're saying here. Are you saying that something is wrong? (more) |
— | almost 3 years ago |
Edit | Post #285956 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285956 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285956 | Initial revision | — | almost 3 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) |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 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) |
— | almost 3 years ago |
Comment | Post #285908 |
About step 3. I would definitely not have that as an automatic step. (more) |
— | almost 3 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) |
— | almost 3 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) |
— | almost 3 years ago |
Comment | Post #285899 |
I updated to a better example (more) |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285811 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285811 |
Post edited: |
— | almost 3 years ago |
Comment | Post #285899 |
I removed that part. I was remembering completely wrong. (more) |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285899 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285899 | Initial revision | — | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285898 | Initial revision | — | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285897 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285897 | Initial revision | — | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285896 | Initial revision | — | almost 3 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) |
— | almost 3 years ago |
Edit | Post #285894 | Initial revision | — | almost 3 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) |
— | almost 3 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) |
— | almost 3 years ago |
Comment | Post #285883 |
Updated the question (more) |
— | almost 3 years ago |
Edit | Post #285883 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285883 |
Post edited: |
— | almost 3 years ago |
Edit | Post #285811 |
Post edited: |
— | almost 3 years ago |
- ← Previous
- 1
- 2
- 3
- 4
- Next →