pointers

Bit Shifts on a C Pointer?

I'm in the middle of this C project that I wish to make very memory efficient. In several cases, I am using the void *s of a dynamic array structure I wrote in order to hold bits. I wish to use all 64 (in this case) bits. I soon realized that you cannot actually do any bit manipulation on a pointer. So my solution was the following: ...

Isn't an array/arrayname always a pointer to the first element in C?

What's going in below isn't an arrayname always a pointer to the first element in C? int myArray[10] = {0}; printf("%d\n", &myArray); /* prints memadress for first element */ printf("%d\n", myArray); /* this prints a memadress too, shows that the name is a pointer */ printf("%d\n",sizeof(myArray)); /* this prints size of the whole arr...

passing string as an argument in C

I am having a function: int getparam(char *gotstring) and i am passing the a string argument to it i.e., a string for eg: char *sendstring="benjamin" instead of teh above declaration can i use int getparam(char gotstring[]) which one is better. and if i have to use int getparam(char gotstring[]) what are all the other changes...

How to get address of base stack pointer

I am in the process of porting an application from x86 to x64. I am using Visual Studio 2009; most of the code is C++ and some portions are plain C. The __asm keyword is not supported when compiling towards x64 and our application contains a few portions of inline assembler. I did not write this code so I don't know exactly what et is su...

Calling pointer-to-member function in call for a function passed to a template function.

This is the provided function template I'm trying to use: template <class Process, class BTNode> void postorder(Process f, BTNode* node_ptr) { if (node_ptr != 0) { postorder( f, node_ptr->left() ); postorder( f, node_ptr->right() ); f( node_ptr->data() ); } } This is my call, and the function I'm passing: v...

Casting a pointer to a sub-class (C++)

Hi I'm developing a game and I need to find a way of getting the value of a certain 'map block' in the game (in char format). I have a class DisplayableObject which takes care of all sprites, and a sub-class ThreeDCubePlayer which takes care of the player object. For ease of rendering/updating everything, all DisplayableObjects are stor...

Read data into a float array in C

i am making a program where i need to load some floating point data of the format from a file 103.45 123.45 456.67 ...... i was wondering how to store these data directly into a array of floating point numbers using fread(). i guess it is not that hard using pointers but i am not so good with them. can anyone tell me how ...

Interop assembly pointer length

Why does Visual Studio sometimes turn SAME pointer parameters in COM libraries into uint and sometimes to ulong? I have a COM library that has some methods with parameters such as [ in ] ULONG_PTR ParentWindow When I reference this library on my desktop computer, the interop assembly turns the ULONG_PTR into uint. When I do the same o...

Printf seems to mess the output of a simple C program

Hi there. I have some code to add fractions. #include <stdio.h> #include <stdlib.h> struct frac { int enumerator; int denominator; }; typedef struct frac frac_t; frac_t *Add(frac_t *b1, frac_t *b2) { frac_t rfrac; frac_t *p; p = &rfrac; (*p).enumerator= ((*b1).enumerator* (*b2).denominator) + ((*b2).enumerator* (*b1).d...

Passing C++ structure pointer from Perl to arbitary dll function call

Hi, I am using Win32::API to call an arbitary function exported in a DLL which accepts a C++ structure pointer. struct PluginInfo { int nStructSize; int nType; int nVersion; int nIDCode; char szName[ 64 ]; char szVendor[ 64 ]; int nCertifi...

Rewriting a returned pointer to an output parameter

I'm playing around with the openSSL library and it requires me to brush up on pointers, and I'm having difficulty. I have a objective-c method: -(unsigned char *)encryptTake1:(unsigned char *)input inputLength:(int)inLen outputLength:(int*)outLen; It takes some data, encrypts it and returns a pointer to the data and the length of the...

find value in a.txt , put it as an input in b.txt using batch

Hi guys, I am looking for your help on the following. I am going to read a value in a.txt, and put it as an input for b.txt The problem is, in a.txt, the value will keep changing due to iteration process. So, it is better to point a pointer to WHERE the value will appear. Ex. (as in a.txt file) X = 12345 so, i would like to point wh...

How to initialize static const pointer in a class ?

class School { static const int *classcapacity; }; This expression is from my exam and it need to get initialized how can i do that ? ...

Qt QString cloning Segmentation Fault

Hi, I'm building my first Qt app using Qt Creator, and everything was going fine until I started getting a strange SIGSEGV from a line apparently harmless. This is the error: Program received signal SIGSEGV, Segmentation fault. 0x0804e2fe in QBasicAtomicInt::ref (this=0x0) at /usr/lib/qt/include/QtCore/qatomic_i386.h:120 By back...

What's the point of having pointers in Go?

I know that pointers in Go allow mutation of a function's arguments, but wouldn't it have been simpler if they adopted just references (with appropriate const or mutable qualifiers). Now we have pointers and for some built-in types like maps and channels implicit pass by reference. Am I missing something or are pointers in Go just an un...

C pointers vs. Objective-C pointers

Hello! I'm coming from an Objective-C background and am trying to expand my knowledge in C. One thing has me confused, however, and that's the difference between pointers in C and Obj-C. As you can see in the examples below, things seem to behave a bit differently between both languages, and I was wondering if you could help explain w...

Calling base class functions through derived pointers

( Objective C ) How would I call a base class function using a derived pointer where foo is overridden in the derived class. Essentially the equivalent of this C++ code base* b_ptr = 0 ; derived* d_ptr = new derived() ; d->base::foo() ; I would think this should be fairly simple. Do I need to use a selector? ...

Casting a void pointer (data) to a function pointer

I know this has been asked before but none of the cases I've seen here are like this one. I am importing some API functions at runtime, the general declaration on those functions would be like: // Masks for UnmapViewOfFile and MapViewOfFile typedef BOOL (WINAPI *MyUnmapViewOfFile)(LPCVOID); typedef LPVOID (WINAPI *MyMapViewOfFile)(HAND...

C pointer arithmetic for 2D arrays

// strings is a 2D array (each string is 11 bytes long) char strings[][11] = {"0123456789", "2222244444", "3333366666"}; printf("String 3 Character 2 is %c\n", strings[2][1]); How can I code this print statement using pointer arithmetic instead of the strings[2][1] ? ...

What does this statement mean? "good C++ programming typically doesn't use pointers in complicated ways."

In this other question in the winning answer I read: ... good C++ programming typically doesn't use pointers in complicated ways. What does it mean to not use pointers in complicated ways? (I'm really hoping that this isn't a subjective question) ...