Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
2 votes
2 answers
121 views

I'm asking this question from the perspective of a compiler developer – I want to know whether a particular potential optimisation is valid (because all programs that the optimisation would break have ...
-6 votes
2 answers
282 views

I want to try catch the free(hello); so that the free(world); can still be executed for freeing all allocated memory in the main program. int main() { const char *hello = "Hello World"; ...
4 votes
2 answers
228 views

I don't know how to reset the value field inside the Hello struct. It's a pointer pointed to an outside passed input argument. typedef struct Hello { void *value; } Hello; Hello* create_hello() { ...
2 votes
3 answers
209 views

I want to write a computer programme that will do the following things : 1a. It will make an array 3 characters long. £££ 2a. It will then initialize the array with the string "{_}" and ...
3 votes
2 answers
168 views

Is it safe to call free in the example below: size_t len = 10; char* buffer = static_cast<char*>(malloc(len)); std::string_view sview(buffer, len); free(sview.data()) Why do I need this? I have ...
0 votes
2 answers
162 views

I am confused about &str[0], which is equal to str. If I can do str = NULL, why can’t I do &str[0] = NULL or why does it not work? Also, since free(str) and free(&str[0]) both work to free ...
3 votes
2 answers
130 views

I've been following an article that walks through implementing primitive versions of malloc and free. After finishing the allocator, I wanted to test it using Valgrind, so I added the following lines ...
1 vote
2 answers
122 views

I'm not sure why my valgrind is spitting heap errors and I've been tracing my code left and right. I have some code, but I'm not sure if more code is needed. My jobs.h #include "piper.h" #...
3 votes
1 answer
120 views

I'm just confused as to why this keeps giving me an error. If I just fread the file in and don't assign the last index to the null terminator, I can free the memory after using it. However, if I do ...
5 votes
6 answers
692 views

Suppose that I need to malloc three times and I would like to make an early return if one of the malloc calls have failed. My first try: void test(void) { int *a, *b, *c; a = malloc(sizeof(*...
0 votes
0 answers
54 views

I am facing a problem in my application. I'm using the Office Viewer to view office files, but when the document loads, it appears with its own options bar (for example, to create a copy or turn on ...
1 vote
0 answers
59 views

I am trying to implement a simple memory allocator. Essentially trying to copy the function malloc() and free(void *ptr) in C. I initialize a region of memory using sbrk(). In my custom malloc ...
1 vote
1 answer
139 views

I am writing some random code and I wanted to know if there is there anything that defines how freeing memory returned like this works or if it is just undefined behavior. struct a *get() { static ...
0 votes
2 answers
140 views

The following code allocates 256 bytes for a character array and then replaces the space with 0円 (similar to what strtok and strsep do). #include <stdlib.h> #include <string.h> int main() ...
1 vote
1 answer
175 views

I am not from a computer science background and have been trying to learn Data Structures using C programming. I have made some binary tree programs and realised that I have used malloc() left and ...

15 30 50 per page
1
2 3 4 5
...
175

AltStyle によって変換されたページ (->オリジナル) /