pointers

C++/CLI how to.

Hi all, I am learning C++/CLI and stuck with a problem. I have a header file that looks like typedef struct _DATA_INFO { WORD ONE WORD TWO WORD THREE } DATA_INFO public ref class ManagedDataInfo { DATA_INFO* info; public ManagedDataInfo() { info=new DATA_INFO(); } ...

C: Why do unassigned pointers point to unpredictable memory and NOT point to NULL?

A long time ago I used to program in C for school. I remember something that I really hated about C: unassigned pointers do not point to NULL. I asked many people including teachers why in the world would they make the default behavior of an unassigned pointer not point to NULL as it seems far more dangerous for it to be unpredictable. ...

How to convert char* to unsigned short in C++

I have a char* name which is a string representation of the short I want, such as "15" and need to output this as unsigned short unitId to a binary file. This cast must also be cross-platform compatible. Is this the correct cast: unitId = unsigned short(temp); Please note that I am at an beginner level in understanding binary. ...

How do I use C functions that have "this" arguments in a C++ program?

I want to copy and paste a C function I found in another program into my C++ program. One of the function arguments uses the "this" pointer. void cfunction( FILE *outfilefd, const VARTYPEDEFINED this); The C++ compiler errors here on the function prototype: error C2143: syntax error : missing ')' before 'this' How do I make this...

Pointers in Python?

I know Python doesn't have pointers, but is there a way to have this yield 2 instead >>> a = 1 >>> b = a # modify this line somehow so that b "points to" a >>> a = 2 >>> b 1 ? Here's an example: I want form.data['field'] and form.field.value to always have the same value. It's not completely necessary, but I think it would be nice....

C question related to pointers and arrays

Hi, Basically in the code below, my final array does not seem to have the contents from function1(). Any ideas on why I can't get this to work ? Thanks. #include <stdio.h> #include <string.h> #include<stdlib.h> unsigned char *function1() { unsigned char array2[] = { 0x4a,0xb2 }; return (array2 ); } main() ...

Double Pointer question

Greetings all, Please take a look at following code: #include <stdio.h> #include <iostream> using namespace std; typedef struct MyType{ int num1; }; void test(MyType **src) { MyType *ret=new MyType; ret->num1=666; *src=ret; } int main(){ MyType *mSrc; test(&mSrc); printf("%d Address\n",mSrc); printf("%d Value \n",mSrc->num1)...

Error: Cannot add two pointers

It gives the error in the title about this piece of code: string DDateTime::date2OracleDate(DATE Date) { string s; s="TO_DATE('" + DateFormat("%d/%m/%Y",Date) + "','dd/MM/YYYY')"; return s; } I don't understand how that is possible, no pointers involved.... EDIT: string DDateTime::DateFormat(string sFormat,DATE Date) { ...

Time for deleting pointers

Hei community, I've got a small question concerning the deletion of pointers. I am working with pointer-to-pointer matrices of Dimension 1024x1024. Since I am creating them dynamically, I delete the allocated space for them at the end of the program. But doing this in the usual loop costs quite a lot of time - I measured about 2sec usi...

Take care about precedence of * and ++ in C/C++, (and any keystroke when programming)

Somebody write this function void strToUpper(char *p) { while (*p) { *p = TOUPPER(*p); *p++; //<-- Line to pay attention } } I asked, why do you put the * before p++? answer: because "It's the same", I corrected the code and then stay angry for a while, because both really work the same... void strToUpper...

wchar_t pointer

What's wrong with this: wchar_t * t = new wchar_t; t = "Tony"; I thought I could use a wchar_t pointer as a string... ...

Function that returns a pointer to const 2-d array (C++)

I'm an intermittent programmer and seem to have forgotten a lot of basics recently. I've created a class SimPars to hold several two-dimensional arrays; the one shown below is demPMFs. I'm going to pass a pointer to an instance of SimPars to other classes, and I want these classes to be able to read the arrays using SimPars accessor fun...

TOUGH: Dealing with deeply nested pointers in C++

I define this structure: struct s_molecule { std::string res_name; std::vector<t_particle> my_particles; std::vector<t_bond> my_bonds; std::vector<t_angle> my_angles; std::vector<t_dihedral> my_dihedrals; s_molecule& operator=(const s_molecule &to_assign) { res_name = to_assign.res_name; my_particles = to_assign.m...

Prefixes for C/C++ data members / objects

I've been getting more and more involved in C / C++ programming lately and have noticed a trend in the way people name datatypes in their code. I always see prefixes such as p, m, ui, etc. For example: mPlayerNames, pData, uiNumResets I think I get it, but just to confirm: Do these prefixes indicate the data type? ie: mData -> Matrix ...

Need help deciphering gprof output

I am pretty sure this has something to do with a vector of void function pointers, but I can't really make anything out of it. Can someone break this down for me? __gnu_cxx::__normal_iterator<unsigned long long const*, std::vector<unsigned long long, std::allocator<unsigned long long> > >::difference_type __gnu_cxx::operator-<unsigned ...

C attempt to difference a generic pointer

Hello, I try to call g_io_scheduler_push_job(job_func, &param, NULL, G_PRIORITY_HIGH, generator_cancellable); In my C/gtk+ application for runing job_func in another thread then main program. But have segfault when i call this function, and debugger sad that: ** userdata attempt to difference a generic pointer** My job_func: gbool...

How to reverse data using an array of pointers (parse binary file)

Hey I am parsing a binary file using a specification. The file comes in big-endian mode because it has streamed packets accumulated. I have to reverse the length of the packets in order to "reinterpret_cast" them into the right variable type. (I am not able to use net/inet.h function because the packets has different lengths). The read...

private object pointer vs object value, and returning object internals

Related to: http://stackoverflow.com/questions/2625719/c-private-pointer-leaking According to Effective C++ (Item 28), "avoid returning handles (references, pointers, or iterators) to object internals. It increases encapsulation, helps const member functions act const, and minimizes the creation of dangling handles." Returning objects ...

In C, is it necessary to free a pointer at exit?

Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed? In C, is it necessary to free a pointer at exit? When the program exists, does it free memory from pointers still pointing to an allocated block? Is it dependent on the OS? ...

Returning char* / Visual Studio debugger weirdness

We're getting some funny behavior in the Visual Studio debugger with the following. I'm not sure if it's the code or some debugger weirdness (seen stuff like it before). We are trying to return a pointer to an value in an array. The weird behavior is that the value of x changes to equal y after func() is called a second time...at least,...