pointers

Why can I not initialize an array by passing a pointer to a function?

I know this has a really simple explanation, but I've been spoiled by not having to use pointers for a while. Why can't I do something like this in c++ int* b; foo(b); and initialize the array through... void Something::foo(int* a) { a = new int[4]; } after calling foo(b), b is still null. why is this? ...

Copying C-Style String to Free Store Using Only Dereference

As said in the title, the goal is to copy a c-style string into memory without using any standard library functions or subscripting. Here is what I have so far [SOLVED] #include "std_lib_facilities.h" char* strdup(const char* p) { int count = 0; while(p[count]) ++count; char* q = new char[count+1]; for(int i = 0; i < c...

Call a selector that takes a char* from PyObjC

I'm trying to use a private framework with PyObjC. I've got this so far: from AppKit import * from Foundation import * import objc framework="/System/Library/PrivateFrameworks/DSObjCWrappers.framework" objc.loadBundle("DSObjCWrapper", globals(), framework) directory = DSoDirectory.alloc() directory.initWithHost_user_password_("server...

Differences between pointer initializations

I am speaking in Standard, K&R C. Given: const char a[] = {1, 2, 3}; const char *p = NULL; Are these two statements equivalent: *p = a; p = a; Each of them would be on the third line of the snippet. 1 and 2 certainly don't look the same. What's the difference between the two then? ...

Exception when using strncpy

Hi The following code fragment ends in an exception when executing the strncpy funtion: #define MAX_FILENAME_LEN 127 typedef struct { unsigned long nameLength; char name[MAX_FILENAME_LEN + 1]; } filestructure; char *fileName; strncpy( fileName, filestructure->name, MAX_FILENAME_LEN ); *( fileName + MAX_FILENAME_LEN+1 ) = 0; Ayone ...

Function Pointer in C

How can I create a "function pointer" (and (for example) the function has parameters) in C? ...

Lua scripting implementation

Hello, I'm currently working on implementing Lua into one of the applications that I'm working on. Currently I'm just using the C api and registering functions using lua_register, but I'd like to be able to pass static and non static function pointers to certain class methods. I've found certain libraries on the net, but since I need...

What exactly is nullptr in C++0x?

Most of C++ programmers are waiting for C++0x. An interesting feature and a confusing one (at least for me) is the new nullptr. Well, no need anymore for the nasty macro NULL. int* x = nullptr; myclass* obj = nullptr; Still, I am not getting how nullptr works. For example, Wikipedia article says: C++0x aims to correct this by i...

Extern and Static Pointers in C

Hi what could be the usage of static and extern pointer ?? if they exist ...

Hex dump from memory location

Hi I use a pointer to specify some kind of "shared memory" which I use to exchange data between different processes/threads. Now I would like to have a hex dump of the content of the shared buffer. Does anyone know how to do that? thanks, R ...

How to serialize a pointer into an array of ints?

I know that converting a pointer to one int is unsafe, because the pointer can be bigger than the int in some architectures (for instance in x86_64). But what about converting the pointer to several ints, an array of them? If the pointer size is 2 times bigger than int then convert pointer* to int[2]. The number of needed ints then is ...

Array of pointers causes leaks

Hi I have this code -(void)setUserFilters{ //init the user filters array userFilters = [[NSMutableArray alloc] init]; SearchCriteria *tmpSc= [[SearchCriteria alloc] init]; for(int i=0;i<[searchFilters count];i++) { tmpSc=[self.searchFilters objectAtIndex:i]; if(tmpSc.enabled==TRUE) [userFilters addObject:tmpSc]...

Differences between heap pointer allocation

I have the following data structures: struct Inner { int myValue; }; struct Outer { Inner* inner; }; Option 1 If I do the following: Outer outer; outer.inner = NULL; outer.inner = new inner; inner* pInner = outer.inner; and then add a watch for the following 2 values: outer.inner pInner then they are both non-NULL, a...

How to cast a string to a function pointer in C?

Possible Duplicates: call a function named in a string variable in c Dynamically invoking any function by passing function name as string I have certain functions.. say, double fA1B1C1( .. ) { ... } double fA2B2C3( .. ) { ... } double (*fptr)( .. ); fptr myfunc; These functions are already defined. So...

Deleting pointer sometimes results in heap corruption

I have a multithreaded application that runs using a custom thread pool class. The threads all execute the same function, with different parameters. These parameters are given to the thread pool class the following way : // jobParams is a struct of int, double, etc... jobParams* params = new jobParams; params.value1 = 2; params.value2 ...

Array of Pointers

How can I get an array of pointers pointing to objects (classes) ? I need to dynamically allocate space for them and the length of array isn't determined until run-time. Can any one explain and tell me how to define it? and possibly explain them how it works, would be really nice :) ...

What is the difference between NULL, '\0' and 0

In C, there appear to be differences between various values of zero -- NULL, NUL and 0. I know that the ASCII character '0' evaluates to 48 or 0x30. The NULL pointer is usually defined as: #define NULL 0l In addition, there is the NUL character '\0' which seems to evaluate to 0 as well. Are there times when these three values can n...

The C++ implicit this, and exactly how it is pushed on the stack.

Hi: down to business: I need to know whether, when a class method in C++ is called, the implicit 'this' pointer is the first argument, or the last. i.e: whether it is pushed onto the stack first or last. In other words, I'm asking whether a class method, being called, is taken by the compiler to be: int foo::bar(foo *const this, int a...

Deleting a pointer a different places results in different behaviors (crash or not)

This question is a refinement of this one, which went in a different direction than expected. In my multithreaded application, the main thread creates parameters and stores them : typedef struct { int parameter1; double parameter2; float* parameter3; } jobParams; typedef struct { int ID; void* params; } jobData; s...

basic pointer question in c++ program

I looking for a clarification regarding the pointers. I have compiled the following code in bordland c++ 5.5.1 without any errors. But while i am trying to execute gives a core error. int main () { int x=10,y=20; int &a=x; int &b=y; int *c; int *d; *c=x; *d=y; return 0; } Basically I am trying to ...