typedef struct temp
{
int a,b;
char *c;
temp(){ c = (char*)malloc(10);};
~temp(){free(c);};
}temp;
int main()
{
temp a;
list<temp> l1;
l1.push_back(a);
l1.clear();
return 0;
}
giving segmentation fault.
...
How does one differentiate between pointers and references at runtime? For example, if I wanted to free a pointer of a data type without knowing whether it were a pointer or not how would I do so? Is there any method to tell if a variable has been allocated on the stack or through malloc()?
void destInt(int* var)
{
free(var);
}
int...
Hello,
Awhile ago I asked you another question(Click here to view the question).
This is my problem when using that source file you gave me:
public unsafe struct tPacket_5000_E
{
public Int16 size;
public Int16 opcode;
public byte securityCount;
public byte securityCRC;
public byte flag;
fixed byte blowfish[8];...
C++ code:
struct tPacket
{
WORD word1;
WORD word2;
BYTE byte1;
BYTE byte2;
BYTE array123[8];
}
static char data[8192] = {0};
...
some code to fill up the array
...
tPacket * packet = (tPacket *)data;
We can't do that as easy in C#.
Please note there is an array in the C++ structure.
Alternatively, using this sou...
Hi,
I am having quite a bit of trouble with trying to push_back an object of my custom class to a vector of pointers with my custom class as the type. Please see the code below along with the error received. I am using Eclipse with the CDT plugin and OpenCV on windows xp.
I have spent so much time trying to find an answer but to no ava...
Hello,
I have a function that generates a CRC check byte based on the content of any packet.The problem is in translating the function from C++ to C#
C++ code:
unsigned char GenerateCheckByte( char* packet, int length, unsigned long seed )
{
if( !packet ) return 0;
unsigned long checksum = 0xFFFFFFFF;
length &= 0x7FFF;
char* ptr = pac...
Duplicate
Do you use NULL or 0 for pointers in C++?
When dealing with NULL pointers one can do this
if(ptr != NULL){ ... }
or this
if(ptr != 0){ ... }
Are there reasons to prefer one over the other in C++?
...
I'm having a problem saving a vary large database type in Delphi. It contains an array[1..3500] of TItem, which in turn has two arrays[1..50] and [1..20]. I get a stack overflow unless I set the variable as a Pointer and use the GetMem, FreeMem commands below, but then I can't save it. Code is below.
procedure TDatabase.SaveDB;
var
...
Use case:
class B {
int b;
public:
int getB() {
return b;
}
};
class A {
B *b;
public:
int getB() {
if (b ) { //How can I avoid the null check for b here
return b->getB();
}
}
}
...
What are some ways you can shoot yourself in the foot when using boost::shared_ptr? In other words, what pitfalls do I have to avoid when I use boost::shared_ptr?
...
Alright, I think we all agree that what happens with the following code is undefined, depending on what is passed
void deleteForMe(int* pointer)
{
delete[] pointer;
}
The pointer could be all sorts of different things, and so performing an unconditional delete[] on it is undefined. However, let's assume that we are indeed passing...
I'm working on a small little thing here for school. After hours of researching, and a ton of errors and logic reworking I've almost completed my little program here.
I'm trying to take user input, store it into the string, get a character array from the string ( dont ask why, I just have to put this into a character array ), then get t...
I'm trying to use python ctypes to use these two C functions from a shared library:
bool decompress_rgb(unsigned char *data, long dataLen, int scale)
float* getRgbBuffer()
The first function is working fine. I can tell by putting some debug code in the shared library and checking the input.
The problem is getting the data out. The RG...
EDIT: ah, there it is! Problem solved, thank you! (Bug was elsewhere, not in the copy function.)
I'm working with a program that uses two-dimensional arrays of Strings (probably not that smart to begin with, but eh), and I'd like to write a function that takes one of these arrays (let's say array1), makes an independent copy, and retur...
I have a dictionary that goes like this:
typedef struct dictNode {
int key;
char *value;
struct dictNode *next;
} Dict;
And a get() function that goes like this:
char *get(const Dict *dict, int key) {
if(!dict) return NULL;
Dict *currPtr = dict;
while(currPtr) {
if(currPtr->key == key) {
return cu...
I have a small gif that I can use as a mouse pointer with a browser by doing something like:
.myclass
{
cursor: url("mycursor.gif");
}
This works OK except that the hotspot is in the wrong place. Anyone know of any OSX Leopard software I can use to set the hotspot? I might be able to do it with Rezilla but I don't know ...
In ANSI C, offsetof is defined as below.
#define offsetof(st, m) \
((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))
Why won't this throw a segmentation fault since we are dereferencing a NULL pointer? Or is this some sort of compiler hack where it sees that only address of the offset is taken out, so it statically calculates the...
I would like to dynamically control code execution using a pointer, basically a function pointer without the stack frame. Execution does not return to the calling location, but to a single point.
TopOfLoop:
...
Jump(x)
x1:
...
continue
x2:
...
continue
etc.
Is this possible in c#? Thanks.
...
Hey all. I'm working on a project for school where I need to pass a few parameters by reference through multiple functions. I understand how I can pass by reference from where the variables are declared to another function, like this:
main() {
int x = 0;
int y = 0;
int z = 0;
foo_function(&x, &y, &z);
}
int foo_function(int* x, int* ...
Hi,
Can I expect that any "data" pointer in user space programs lies in a safe distance from the addresses 0 and 0xffffffff..., so that I can safely add a small offset to the pointer without checking for an overflow? What is the largest positive n for which I can safely assume that p + n doesn't overflow when p is a char pointer into a ...