In the past, in C and C++ land, nested pointer dereferencing was considered, by some, to be a relatively expensive operation if executed in a tight loop.
You wouldn't want to get caught with:
for (int i = 0; i < 10000000; i++)
{
j->k->l->m->n->o->p->dosomeworknowthatwereherewhynoteh();
}
because you might lose precious millisecond...
I'm trying to do some refactoring of code, and have run into a problem. The program has a data manager that returns pointers to arrays of structures as a void*. One of the new types of data, instead of having a single pointer to an array of structures, has two pointers to arrays of numbers. The problem is that all the processing code ...
In C++, void somefunction(int) passes a value, while void somefunction(int&) passes a reference. In Java, primitives are passed by value, while objects are passed by reference. How does python make this decision?
Edit: Since everything is passed by reference, why does this:
def foo(num):
num *= 2
a = 4
foo(a)
print(a)
print '4'...
I am releasing things but the memory seems to still be there according to instruments. Am I just releasing the pointer and not the actual data? How do I release THE DATA in objective-c? What's the difference between [anObject release] or [&anObject release]???? Please excuse my lack of knowledge on the subject of memory and pointers.
...
I have a struct as follows, with a pointer to a function called "length" that will return the length of the chars member.
typedef struct pstring_t {
char * chars;
int (* length)();
} PString;
I have a function to return the length of the characters from a pointer to a PString:
int length(PString * self) {
return strlen(se...
Does pointers in C and C++ support comparison operators (>, <, etc.) in standard? I want to compare array positions to be precise.
...
I would like to know architectures which violate the assumptions I've listed below. Also I would like to know if any of the assumptions are false for all architectures (i.e. if any of them are just completely wrong).
sizeof(int *) == sizeof(char *) == sizeof(void *) == sizeof(func_ptr *)
The in-memory representation of all pointers fo...
Consider:
int a[2] = {0,1};
int *address_of_second = (&a[1]);
I assume this works because it's translated to &*(a+1) and then the & and * cancel each other out, but can I count on it, or is it compiler-specific? That is, does the C standard have anything to say about this?
Is this a decent way to write?
Personally I think that writi...
I've got a very simple line of code in Objective-C:
if ((selectedEntity != nil) && [selectedEntity isKindOfClass:[MobileEntity class]])
Occasionally and for no reason I can tell, the game crashes on this line of code with an EXC-BAD-ACCESS. It usually seems to be about the time when something gets removed from the playing field, so I'...
I am using C. I am having issues with using pointers for the fscanf function. When I try to do:
int *x;
/* ... */
fscanf(file, "%d", x[i]);
My compiler gives me a warning saying "format argument is not a pointer" and the code just doesn't run (I get a message saying "Water.exe has stopped working"). If I replace x with *x, it just doe...
I'm using a vector of pointers to objects. These objects are derived from a base class, and are being dynamically allocated and stored.
For example, I have something like:
vector<Enemy*> Enemies;
and I'll be deriving from the Enemy class and then dynamically allocating memory for the derived class, like this:
enemies.push_back(new M...
I was looking at the following code I came across for printing a string in reverse order in C using recursion:
void ReversePrint(char *str) { //line 1
if(*str) { //line 2
ReversePrint(str+1); //line 3
putchar(*str); //line 4
}
}
I am relatively new to C and am confused by line 2. *str fr...
I have a DLL containing a C function with a prototype like this:
int c_read_block(uint32 addr, uint32 *buf, uint32 num);
I want to call it from Python using ctypes. The function expects a pointer to a chunk of memory, into which it will write the results. I don't know how to construct and pass such a chunk of memory. The ctypes documen...
Hi
It has been a while that I used pointers and I just wanna quickly check how I can initialize an integer pointer?
a) int *tmpPtr = 0;
b) int *tmpPtr = null;
c) int a = 0;
int *tmpPtr = &a;
EDIT
Thanks for all your answers so far. The funny thing is, that if I intitalize
the pointer as follows, then the mem::copy operation wor...
I am using g++. I am using code that had a main(int,char**), renamed so I can call it. I looked at http://stackoverflow.com/questions/779910/should-i-use-char-argv-or-char-argv-in-c, where char** is said to be equivalent to char* []. This does not appear to be true in c++ function calls. For example:
void f1(char** p){;}
void f2(ch...
Looking at example under "Pointers to classes" (very bottom)
How is it that we can use the dot operatior here:
CRectangle * d = new CRectangle[2];
...
d[1].set_values (7,8);
if d is a pointer?
Same question for the lines:
cout << "d[0] area: " << d[0].area() << endl;
cout << "d[1] area: " << d[1].area() << endl;
Also, For...
In C specifically (i suppose this also applies to C++), what is the difference between
char str[4] = "abc";
char *cstr = {"abc"};
Problems arise when i try and pass my "abc" into a function that accepts char**
void f(char** s)
{
fprintf(stderr, "%s", *s);
}
Doing the following yields a compiler error. If cast to char** (to make c...
How can we access variables of a structure? I have a struct:
typedef struct {
unsigned short a;
unsigned shout b;
} Display;
and in my other class I have a method:
int NewMethod(Display **display)
{
Display *disp=new Display();
*display = disp;
disp->a=11;
}
What does **display mean? To access variables of struct I h...
If I write
int *columns[32];
am I defining an array with 32 pointers to ints?
Or is it a pointer to an array of 32 ints?
How do I differentiate between the two? Is there a difference?
...
Hey, In C++, I have a vector of type:
vector<BaseClass*> myVector;
In which, I insert (push_back) pointers of derived classes into it.
Now, I want to pop back its elements so I do this:
vector<ADlgcDev*>::iterator iter;
for (iter = myVector.rbegin(); iter != myVector.rend(); iter++)
{
// but before I pop it, I need to shutdown it ...