What difference there is when you access to another struct by value or by a pointer?
When should be used each one of them?
type foo_ struct {
st uint8
nd uint8
}
type bar struct {
rd uint8
foo foo_
}
type barP struct {
rd uint8
foo *foo_
}
...
I have a structure usually containing a pointer to an int. However, in some special cases, it is necessary that this int pointer points to another pointer which then points to an int. Wow: I mentioned the word pointer 5 times so far!
Is this even possible?
I thought about it that way: Instead of using a second int pointer, which is m...
If one could put an array of pointers to child structs inside unsafe structs in C# like one could in C, constructing complex data structures without the overhead of having one object per node would be a lot easier and less of a time sink, as well as syntactically cleaner and much more readable.
Is there a deep architectural reason why ...
What is this syntax for in C++? Can someone point me to the technical term so I can see if I find anything in my text?
At first I thought it was a prototype but then the = and (*fn) threw me off...
Here is my example:
void (*fn) (int&,int&) = x;
...
Hi.
I would like to know what do you use to sketch relations between different entities in C/C++. This can be a very broad issue, so I'll try to clarify a bit more my question and give an example.
I'm looking for something that is simple enough as a user, and let me sketch easily containers, pointers, etc... in an informal way.
The aim ...
In C (or C++ for that matter), pointers are special if they have the value zero: I am adviced to set pointers to zero after freeing their memory, because it means freeing the pointer again isn't dangerous; when I call malloc it returns a pointer with the value zero if it can't get me memory; I use if (p != 0) all the time to make sure pa...
The constant 0 is used as the null pointer in C and C++. But as in the question "Pointer to a specific fixed address" there seems to be some possible use of assigning fixed addresses. Is there ever any conceivable need, in any system, for whatever low level task, for accessing the address 0?
If there is, how is that solved with 0 being ...
In a project I'm writing code for, I have a void pointer, "implementation", which is a member of a "Hash_map" struct, and points to an "Array_hash_map" struct. The concepts behind this project are not very realistic, but bear with me. The specifications of the project ask that I cast the void pointer "implementation" to an "Array_hash_ma...
I have a stucture:
typedef structure student {
char *name;
char *surname;
int age;
} Student;
I need to write it to binary file.
Student *s = malloc(sizeof(*s));
I fill my structure with data and then i write in to the file:
fwrite(s, sizeof(*s), 1, fp);
In my file doesnt exist a name and surname, it have an adresses of c...
One of job interview questions on C pointers here is the following: what is null pointer assignment error?
I've googled for a while and don't see any reasonable explanation. What is that? Trying to write through a null pointer? Something architecture- or environment-specific? What exactly is that error?
...
I'm using a library which for one certain feature involves variables like so:
extern const u8 foo[];
extern const u8 bar[];
I am not allowed to rename these variables in any way.
However, I like to be able to access these variables through an array (or other similar method) so that I do not need to continually hardcode new instances ...
I have a loop which goes through a video with some processing/calculations of the images. I want to save the image in the loop with the highest value from the processing, but I'm struggling a bit with storing the image temporally while the loop finishes.
The images/frames are initialized like this
IplImage* frame = 0;
IplImage* maxfram...
int valid (int x, int y) {
return x + y;
}
int invalid (int x) {
return x;
}
int func (int *f (int, int), int x, int y) {
//f is a pointer to a function taking 2 ints and returning an int
return f(x, y);
}
int main () {
int val = func(valid, 1, 2),
inval = func(invalid, 1, 2); // <- 'invalid' does not matc...
Hi,
I'm having problem getting the value from a pointer. I have the following code in C++:
void* Nodo::readArray(VarHash& var, string varName, int posicion, float& d)
{
//some code before...
void* res;
float num = bit.getFloatFromArray(arregloTemp); //THIS FUNCTION RETURN A FLOAT AND IT'S OK
cout << "NUMBER ...
Hello i have the following error:
malloc: * error for object 0x2087000: pointer being freed was not allocated
* set a breakpoint in malloc_error_break to debug
I have no idea what object that is. I don't know how to find it. Can anybody explain to me how (and where) to use malloc_history. I have set a breakpoint in malloc_error_break b...
In the code below I have a function int GetTempString(char Query[]);
calling it in main works fine.
However, when calling the function from a fork the fork hangs (stops running, no errors, no output) before this line: pch = strtok (Query," ,"); the printf shows that the pointer to pch is null. Again this only happens when the fork is ex...
In one header file I have:
#include "BaseClass.h"
// a forward declaration of DerivedClass, which extends class BaseClass.
class DerivedClass ;
class Foo {
DerivedClass *derived ;
void someMethod() {
// this is the cast I'm worried about.
((BaseClass*)derived)->baseClassMethod() ;
}
};
Now, DerivedClass is (in ...
How do I pass a pointer value to an array of the struct;
For example, on a txt I have this:
John Doe;[email protected];214425532;
My code:
typedef struct Person{
char name[100];
char email[100];
int phone;
}PERSON;
int main(){
PERSON persons[100];
FILE *fp;
char *ap_name;
char *ap_email;
char *ap_phone...
Im passing function GetCurrentDate() the pointer to a tm struct.
Within that function I printf the uninitialized data, then the initialized. Expected results.
However when i return the tm struct appears uninitialized.
See console output bellow. What am i doing wrong?
uninitialized date:??? ???-1073908332
01:9448278:-1073908376 -...
Let's say I have this to create a multidimensional array dynamically:
int* *grid = new int*[gridSizeX];
for (int i=0; i<gridSizeX; i++) {
grid[i] = new int[gridSizeY];
}
Shouldn't be possible now to access elements like grid[x][y] = 20?
...