Hi all,
Problem:
I try to deallocate memory pointed by pointer items of an STL list.
This should work fine but in my case, there can be duplicate pointers in the list and I get a double dealloc exception even though I test whether the pointer is NULL or not (see source code below).
How can I solve this problem ?
Environment:
Debian...
I'm trying to use the standard library's qsort to sort an array of wide characters:
wchar_t a = L'a';
wchar_t a1 = L'ä';
wchar_t b = L'z';
wchar_t chararray[] = {b, a, a1};
length = wcslen(chararray);
qsort(chararray, length, sizeof(wchar_t), wcscoll);
Now I think the functions involved have these prototypes:
int wcscoll(const wch...
Possible Duplicate:
Why cant I convert char* to a const char const* in C?
I am curious, why can't I pass a char ** to const char ** function? Where as it is OK to pass char * to a const char * function it seems not to be OK to do it with double pointers. I thought it was always ok to add constness (but not ok to drop constness...
I'm developing a GUI library with a friend and we faced the problem of how to determine whether a certain element should be clickable or not (Or movable, or etc.).
We decided to just check if a function exists for a specific object, all gui elements are stored in a vector with pointers to the base class.
So for example if I have
class...
class Foo {
public:
static const int kType = 42;
};
void Func() {
Foo *bar = NULL;
int x = bar->kType;
putc(x, stderr);
}
Is this defined behavior? I read through the C++ standard but couldn't find anything about accessing a static const value like this... I've examined the assembly produced by GCC 4.2, Clang++, and Visual Studio ...
I have a pointer in a struct. And I passed a struct pointer to this pointer.
But I could not type cast back to this pointer to struct.
public class Test
{
//
Pointer ptr = new Memory(4);
}
public class Temp extends Structure
{
//
}
Test tst = new Test();
Temp tmp = new Temp();
tst.ptr = tmp.getPointer();
...
Temp...
The following code causes a SIGSEGV, but only while debugging.
#include <stdio.h>
#include <stdlib.h>
typedef struct enemy_desc
{
int type;
int x;
int y;
}enemy;
int main()
{
enemy **enemies;
enemies=(enemy **)malloc(sizeof(enemy *)*16);
enemies[0]->type=23;
printf("%i",enemies[0]->type);
return 0;
}
...
I have the following program. However, I can't understand why I have to pass the address of the array. When they are both pointing to the same address. Which is the address of the first element of the array of int's.
I get a warning when I try and do this "assignment from incompatible pointer type":
ptr = var;
Complete source code:
...
Hello, I have a MMORPG emulator, this means it will be handling packets quite a bit.
Currently, I am using pointers for this, as I think when used correctly, they can speed up my server, however I've got two friends, one is telling me to use pointers, he thinks I can use them without running into trouble, my other friends says I should n...
I first process a matrix in cublas, I have already sent it to device and I want to process
some column vector of the matrix, still use cublas function. I first try using pointer arithmetic operation to offset the device pointer from host, but it seems doesn't work.
Is there any way I can process vector in matrix without copying it back t...
I understand that in order to return a string from a function I have to return a pointer. What I don't understand is why a char array is treated somewhat different from, say, integer, and gets destroyed when you exit the function. That's probably because I come from a high-level languages world, but this seems to be equally valid to me:
...
I intend to store strings into an array of pointers to strings and then display them as follows :
char *directions[3];
for(i=0;i<3;i++)
scanf("%s",directions[i]);
for(i=0;i<3;i++)
printf("%s",directions[i]);
but when i run this code ,it gives me segmetation fault ,could someone please correct me?
...
What am I doing wrong here ?
/*
* Consider the following pseudo code !
*/
typedef struct foobar {
unsigned char id, count;
struct foobar *child;
} foobar;
foobar root = (foobar *) malloc( sizeof(struct foobar) );
root->child = (foobar *) malloc( sizeof(struct foobar) );
root->count++;
root->child[0].id = 1;
root->count++;
r...
Hello,
gcc 4.4.3 c89
I have the following source file.
However, I get a stack dump on the following line:
printf("dest: %d [ %s ]\n", i, dest[i]);
The reason is that if fails to break from the for loop. I have tried different conditions in the for loop to try and break before printing.
i != NULL
i != '\0'
i != 0
However, all of...
My main() crashes below when add(4) is called.
As I understand int* add, it should return a pointer to integer. Then, I should be able in main to say:
int * a = add(3);
to return a pointer to int.
Please explain what I'm doing wrong.
#include <cstdlib>
#include <iostream>
using namespace std;
int* add (int a) {
int * c, d;
...
How do I pass the m matrix to foo()? if I am not allowed to change the code or the prototype of foo()?
void foo(float **pm)
{
int i,j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
printf("%f\n", pm[i][j]);
}
int main ()
{
float m[4][4];
int i,j;
for (i = 0; i < 4; i++)
for (j = 0; j ...
hi,
Just getting into C++. I'm getting constantly thrown off track when I see the symbol for multiply (*) being used to denote the dereferencing of a variable
for example:
unsigned char * pixels = vidgrabber.getPixels();
Does this throw other people off? What's the tip for getting my head around this?
Thank you.
p.s. I have an...
As background, I gave an answer to this post a little while ago:
http://stackoverflow.com/questions/3473438/c-return-array-in-a-function/3473448#3473448
And it unintentionally kicked off a really long comment chain about pointers vs. arrays in C++ because I tried to oversimplify and I made the statement "arrays are pointers". Though m...
Which is the better convention of declaring pointers in C++?
MyClass* ptr
(or)
MyClass *ptr
I find the first one meaningful, because i feel like declaring MyClass pointer rather than a MyClass and specifying a type modifier. But i see a lot of books recommending the later convention. Can you give the rational behind the convention...
I have code that interacts with a gridview, and the code is exactly the same for multiple gridviews. So can I do something like this:
Dim gridViewPointer As GridView
If (gridViewNumber = 1) Then
gridViewPointer = GridView1
ElseIf (gridViewNumber = 8) Then
gridViewPointer = GridView8
...
...