Hello,
I'm initializing in a class a pointer to be NULL. Afterwards I check if it is NULL in the same class. But it's not always 0x0. Sometimes it's 0x8 or 0xfeffffff or 0x3f800000 or 0x80 or other strange stuff. In most case the pointer is 0x0 but sometimes it gets altered somehow.
I'm sure that I'm not changing it anywhere in my code...
I trying to find whether the elements of 2 arrayLists are match or not.
But this code give me error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException since some of the elements are null.
How can I solved this problem?
String level []={"High","High","High","High","High","High"};
ArrayList<Object> n = new ArrayList<O...
Quick question: I am a C# guy debugging a C++ app so I am not used to memory management.
In the following code:
for(int i = 0; i < TlmMsgDB.CMTGetTelemMsgDBCount(); i++)
{
CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i);
CMT_SINT32_Tdef id = telm->CMTGetPackingMapID();
ManualScheduleTables.SetManualMsg(i,id);
...
i'm having an issue understanding why the following works:
void doubleAddr(double* source, double** dest)
{
*dest = source;
}
i get a pointer to a double and want to change the double that dest points to:
//usage:
int main()
{
double* num;
double* dest;
doubleAddr(num, &dest);
return 0;
}
thanks in advanc...
char *p="orkut" vs const char *p="orkut"
whats the difference btwn these two...
EDIT
from bjarne stroustrup,3rd edition page 90
void f()
{
char* p="plato";
p[4]='e' // error: assign to const;result is undefined
}
this kind of error cannont be general b caught until run time and implementations differ in their enforcement of thi...
After some painful experiences, I understand the problem of dangling pointers and double free. I am seeking proper solutions.
aStruct has a number of fields including other arrays.
aStruct *A=NULL, *B = NULL;
A = (aStruct*) calloc(1, sizeof(sStruct));
B = A;
free_aStruct(A);
...
//bunch of other code in various places.
...
free_aStruct...
I have just created 2 pointers which has undefined behavior and try to invoke a class member function which has no object created ?
I don't understand this?
#include<iostream>
using namespace std;
class Animal
{
public:
void talk()
{
cout<<"I am an animal"<<endl;
}
};
class Dog : public Animal
{
public:
void talk()
...
I'm a bit confused about the object references. Please check the examples below:
class ListHandler {
public:
ListHandler(vector<int> &list);
private:
vector<int> list;
}
ListHandler::ListHandler(vector<int> &list) {
this->list = list;
}
Because of the internal
vector<int> list;
definition, here I would be wasting memory r...
I have this in my @interface
struct track currentTrack;
struct track previousTrack;
int anInt;
Since these are not objects, I do not have to have them like int* anInt right?
And if setting non-object values like ints, boolean, etc, I do not have to release the old value right (assuming non-GC environment)?
The struct contains objects...
In code:
template<class T,int row, int col>
void invert(T (&a)[row][col])
{
T* columns = new T[col * row];
T* const free_me = columns;
T** addresses = new T*[col * row];
T** const free_me_1 = addresses;
/*cpy addresses*/
for (int i = 0; i < row; ++i)
{
for (int j = 0; j < col; ++j)
{
*addresses = &a[i][j];
++ad...
I'm making a game for the iPhone, and I have a class called Robot.
Then I have a class called View, which renders everything.
I want to send a copy of my Robot, which I defined in my ViewController, and I send it to gameView (which is View *gameView), like this:
robot = [Robot new];
[gameView setRobot: [robot copy]];
I tried to make...
First, please take a look at these code:
class Key;
class Door;
class Key
{
public:
int id;
Door *pDoor;
Key() : id(0), pDoor(NULL) {}
private:
friend class boost::serialization::access;
template <typename A>
void serialize(A &ar, const unsigned int ver)
{
ar & BOOST_SERIALIZATION_NVP(id) & BOOST...
Say I have an object:
struct Foo
{
int bar_;
Foo(int bar) bar_(bar) {}
};
and I have an STL container that contains Foos, perhaps a vector, and I take
// Elsewhere...
vector<Foo> vec;
vec.push_back(Foo(4));
int *p = &(vec[0].bar_)
This is a terrible idea, right?
The reason is that vector is going to be storing its el...
In C#, I need to write T[] to a stream, ideally without any additional buffers. I have a dynamic code that converts T[] (where T is a no-objects struct) to a void* and fixes it in memory, and that works great. When the stream was a file, I could use native Windows API to pass the void * directly, but now I need to write to a generic Stre...
I have a shared structure, and inside it a request structure:
struct shared_data {
pthread_mutex_t th_mutex_queue;
struct request_queue {
int min;
int max;
char d_name[DIR_SIZE];
pid_t pid;
int t_index;
} request_queue[BUFSIZE];
int count;
int data_buffer_allocation[BUFSIZE]...
I have this struct;
#define BUFSIZE 10
struct shared_data {
pthread_mutex_t th_mutex_queue;
int count;
int data_buffer_allocation[BUFSIZE];
int data_buffers[BUFSIZE][100];
};
and I want to allocate one of the data_buffers for a process, for that purpose I execute the following function;
int allocate_data_buffer(int p...
Hi I am a C++ beginner just encountered a problem I don't know how to fix
I have two class, this is the header file:
class A
{
public:
int i;
A(int a);
};
class B: public A
{
public:
string str;
B(int a, string b);
};
then I want to create a vector in main which store either class A or class B
vect...
I am currently learning C by reading a good beginner's book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter on pointers and the -> (arrow) operator came up without explanation. I think that it is used to call members and functions (like the equivale...
Hi,
I'm writing to a text file using the following declaration:
void create_out_file(char file_name[],long double *z1){
FILE *out;
int i;
if((out = fopen(file_name, "w+")) == NULL){
fprintf(stderr, "***> Open error on output file %s", file_name);
exit(-1);
}
for(i = 0; i < ARRAY_SIZE; i++)
fp...
I am new to C and I was reading about how pointers "point" to the address of another variable. So I have tried indirect invocation and direct invocation and received the same results (as any C/C++ developer could have predicted). This is what I did:
int cost;
int *cost_ptr;
int main()
{
cost_ptr = &cost; //...