close
Skip to main content

New answers tagged

Score of 0

c freeing char pointer not working after first time

There are many cases of confusion in your code: [major] missing headers: always post a complete program, missing header files may be a source of problems. [minor] *(newNumber + (newLen - 1)) = *...
Score of 0

When to use Box instead of reference?

References don't "own" their values, so they are fine for parameters, but no use for long-term storage or return values. Box "owns" the value, so it can be stored long term, ...
Score of 3
Accepted

Kotlin/Native/cinterop pointer to custom class

In Kotlin/Native, you cannot declare var with fields in classes that inherit from CPointed. Such classes should reflect the C‑structure in its original form, without unnecessary fields. Otherwise, the ...
Score of 0

Understanding and relationship between Box, ref, & and *

Box isn't really a pointer Box is a wrapper around a pointer that automatically destroys the object and frees the allocation. Similar to unique_ptr in C++ but unlike unique_ptr a valid Box cannot be ...
Score of 0

C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array

$ #Sample code here $ /usr/bin/cat "79986370.c" #include <errno.h> #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct mystruct { char *...
Score of 4

C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array

sizeof(pstring) is the size of a pointer not string. (the_data[index]->mychar)=ouputs undefined behavior due to segfault p_mystruct the_data[2]; declares an array of uninitialized pointers.
Score of 6

C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array

Your code has undefined behavior as a result of a NULL pointer dereference. The variable the_data is an array of struct pointers. Because it is declared at file scope without an initializer, the ...
Score of 0

Identifying what child class object a base class pointer is pointing at

You were trying to apply a C-style cast. But what you failed to do naively, is actually doable if you use dynamic_cast : void identifyChild(Base *obj) { auto as_child1 = dynamic_cast<Child1*>...

Top 50 recent answers are included