pointers

Confusion over C++ pointer and reference topic

What is the difference between the following parameter passing mechanisms in C++? void foo(int &x) void foo(int *x) void foo(int **x) void foo(int *&x) I'd like to know in which case the parameter is being passed by value or passed by reference. ...

error calling function ,[A call to PInvoke function unbalanced the stack]

hello all i have following code , once i run my application i get this error anyone know how i fix this error? ERROR: A call to PInvoke function 'testcamera!EDSDKLib.EDSDK::EdsDownloadEvfImage' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that th...

Can I call memcpy() and memmove() with "number of bytes" set to zero?

Do I need to treat cases when I actully have nothing to move/copy with memmove()/memcpy() as edge cases int numberOfBytes = ... if( numberOfBytes != 0 ) { memmove( dest, source, numberOfBytes ); } or should I just call the function without checking int numberOfBytes = ... memmove( dest, source, numberOfBytes ); Is the check in ...

about malloc() and free() in C

I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node; int main() { node * n; printf("\n%d\n",n->a); n = (node *) malloc ( sizeof( node )); printf("\n%d\n",n->a); n->a = 6; printf("\n%d\n",n->a); free(n); printf("\n%d\n",n->a); n->a = 4; pri...

Return the result of sum of character arrays

Recently in an interview i was asked a question to write a function which takes two character arrays(integers) as input and returns the output character array. Function Signature: char* find_sum(char* a, char* b) How would one approach this? Example scenario: find_sum("12345","32142") = "44487" Note: The number of digits can be ...

C++ Pointer problem

I'm having a pointer problem that I can't seem to figure out. It seems like I've used pointers in this way a 1000 times so I'm not quite sure what is going on here. I have the following code: int iRetVal; CycleCountOrder* cycleOrder = NULL; CycleCountLineItem* cycleLine = NULL; iRetVal = m_CycleCount.GetCCOrderLine(pOneLocation.szO...

C Struct pointer as Parameter

I'm trying to pass a pointer to a struct in C but i cannot: float calcular_media(struct aluno *aluno) { Output warning: C:\WINDOWS\system32\cmd.exe /c gcc main.c aluno.c aluno.c:7:29: warning: 'struct aluno' declared inside parameter list What am I doing wrong? Thank you. ...

Why no "realloc" seems necessary when allocating new element to a char pointer?

I'm trying to create a pointer to char pointer to which I can easily add new elements (strings). I use malloc to create the first 2 dimensions and realloc when I want to add new items. I wrote code with and without realloc and I'm getting the same results. Is this an expected/normal behavior? With realloc: char **p; // create poin...

Is there a difference between int* and Type*?

I am implementing a queue in C. I have a struct like: struct Node { Node* next; Node* previous; // data } Because next and previous are just pointers, does it make a difference if I use Node* or int*? eg: struct Node { int* next; int* previous; // data } ...

Learning C coming from managed OO languages

I am fairly comfortable coding in languages like Java and C#, but I need to use C for a project (because of low level OS API calls) and I am having some difficulty dealing with pointers and memory management (as seen here) Right now I am basically typing up code and feeding it to the compiler to see if it works. That just doesn't feel ...

ColdFusion "system has attempted to use an undefined value" Null Pointers

So I have this error on a feed that magically stopped working for no reason. The error i get is "The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values. " OK, i look up Null pointers and Ben Nadel (god...

Difficulties when attempting to create the Cartesian product of a pointer to char pointer

As input I have a pointer to char pointer containing: {"ab", "cd"} As output I need to create the following Cartesian product: {"abab", "abcd", "cdab", "cdcd"} I created a function that receives "ab, cd" and a pointer to char pointer that is meant to hold the resulting set. Although everything seems to be working fine inside the fu...

Unexpected pointer randomly changes. Why would it change for? Breaks pointer arithmetic.

Hello. Maybe I'm being stupid but I can't figure out why a pointer is being changed in this function. I have included "printf" and "puts" to show the problem. The left braket pointer is changing and invalidates the pointer arithmetic I want to do for string manipulation. Another question I have - Is it dangerous to expect char pointers ...

some keyboard/mouse events cant be caught-xlib programming

hi .. i have a problem with this program ,it lists the current window along with window id thet are running on the system,result is that for a particular window id that i enter i got odd result: for application like firefox or gedit just motion notify event works,non of the other events work?? for my terminal(bash) everything works,key p...

Ada array access

Hello, I'm working in Ada95, and I'm having difficulty figuring out pointers. I have code that looks like the following: type vector is array (1 .. 3) of integer; type vector_access is access vector; my_vec : vector; procedure test is pointer : vector_access := my_vec'access; begin ... end; This fails compilation on...

Using the "This" Pointer in c++

I've been reading about the "this" pointer on various sites (e.g. the MSDN manuals) and understand its basic uses -- returning a copy your own object or using a pointer of it for returns/comparison. But I came across this statement: // Return an object that defines its own operator[] that will access the data. // The temp object is...

Is typedef'ing a pointer type considered bad practice?

Possible Duplicate: Typedef pointers a good idea? I've seen this oddity in many APIs I have used: typedef type_t *TYPE; My point is that declaring a variable of type TYPE will not make it clear that in fact a pointer is declared. Do you, like me, think that this brings a lot of confusion? Is this meant to enforce encapsula...

Pointer alignment in libjpeg

From jmorecfg.h: #define PACK_TWO_PIXELS(l,r) ((r<<16) | l) #define PACK_NEED_ALIGNMENT(ptr) (((int)(ptr))&3) #define WRITE_TWO_PIXELS(addr, pixels) do { \ ((INT16*)(addr))[0] = (pixels); \ ((INT16*)(addr))[1] = (pixels)>>16; \ } while(0) #define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32*)(a...

Get length of string array of unknown length

I have this function: int setIncludes(char *includes[]); I don't know how many values includes will take. It may take includes[5], it may take includes[500]. So what function could I use to get the length of includes? ...

error: request for the member 'query' in connection which is non-class type ' MYSQL*'

// todo: create the connection here // Construct the query string. You were already doing this in your code std::ostringstream query_builder; query_builder << "select pipe_id from pipe where version_id='" << id << "'"; // Convert the ostringstream to a string std::string query_string = query_builder.str(); // Construct a query object...