pointers

When using a restrict Pointer in C, is it OK to change a variable using its initial Identifier?

When using a restrict Pointer in C, is it OK to change the variable using its initial Identifier? For example: int foo = 0; int * restrict fooPtr = &foo; ++(*fooPtr); // Part 1: foo is 1 (OK) ++foo; // Part 2: foo is 2 (Is this OK?) int * fooPtr2 = &foo; ++(*fooPtr2); // Par...

May a pointer ever point to a cpu register?

I'm wondering if a pointer may point to a cpu register since in the case it may not, using reference instead of pointer where possible would give compiler opportunity to do some optimizations because the referenced object may reside in some register but an object pointed to by a pointer may not. ...

when i need pass by pointer (and not by reference)

Can you give me an example when I can't pass argument by reference and I need to use pointer. I've found an example, but I'm not sure. Suppose you have a class D derived from the base class B. You need pointer if you want do so: void function(B* b){...} int main{ D* d; function(d); } ...

Memory and pointers

Hi I have need some some help with some thinking around a task. My task is to create one memory area void *memory = malloc(320); and then use pointers to store texts into this storage place: We want to divide this area into data blocks of 32 bytes, sow we can store: 320/32 = 10 data blocks a 32 bytes. Into one data block I can store...

How do I dereference based on size?

I am trying to print the value pointed to by an address but the problem is I need to dereference this pointer based on the size that is passed to me. So something of this sort: void print(Address addr, Int size) { ... } I am a little confused on how to achieve this. Can someone point me in the right direction? EDIT: Ok so I'm thinkin...

How can a pointer be implemented except storing an address?

Recently I answered another question asking for questions every decent C++ programmer should be able to answer. My suggestion was Q: How does a pointer point to an object? A: The pointer stores the address of that object. but user R.. disagrees with the A I propose to the Q - he says that The correct answer would be "it's implementati...

how does C know dimensions of 2d dynamic array in a function?

I saw this example when I was trying to figure out how to pass pointers to dynamically allocated 2d arrays to functions: void zeroit(int **array, int nrows, int ncolumns) { int i, j; for(i = 0; i < nrows; i++) { for(j = 0; j < ncolumns; j++) array[i][j] = 0; } } I tried it and it works, but I don't understand how. How doe...

pointer as a dummy argument.

I am somewhat puzzled by the following program module test implicit none type TestType integer :: i end type contains subroutine foo(test) type (TestType), intent(out) :: test test%i = 5 end subroutine subroutine bar(test) type (TestType), intent(out) :: test test%i = 6 end subrout...

Visual C++/CLI (CLR) Null pointer

I wan't to implement the following code - the check if the pointer is null or not null. If the pointer points to object, then do sth with that object, if not - skip that code block. My code: ref class EchoClient { private: GameMatrix^ gameMatrix; public: EchoClient(void); EchoClient(GameMatrix^); void do(); }; EchoClie...

What is guaranteed about the size of a function pointer?

In C, I need to know the size of a struct, which has function pointers in it. Can I be guaranteed that on all platforms and architectures: the size of a void* is the same size as a function pointer? the size of the function pointer does not differ due to its return type? the size of the function pointer does not differ due to its param...

c++ and multi pointers

I have a simple problem with pointers. Here is my code: #include <iostream> #include <vector> using namespace std; int main() { typedef float RtPoint[3]; RtPoint** b = new RtPoint*[4]; b[0] = (RtPoint*)new RtPoint; RtPoint* p = b[0]; RtPoint c; (*p)[0] = &(c[0]); (*p)[1] = &(c[1]); (*p)[2] = &(c[2]); ...

variable declaration problem inside struct

I declared a Normal Structure In C: typedef struct arr_struct{ int* original; int size; int first[size/2]; int second[size-(size/2)]; }; when compile it gives me: test.c:11: error: ‘size’ undeclared here (not in a function) any explanation? ...

ANSI C: Passing array by value generates wierd error I can not solve.

When I declare this function: void vLFSR_ParseInput(unsigned char * pucDataArray,unsigned char unCount){} and try to pass it this array unsigned char g_ucUSCI_A0_RXBufferIndex = 0x00; unsigned char g_ucaUSCI_A0_RXBuffer[RXBUFFERSIZE]; with this function call vLFSR_ParseInput(&g_ucaUSCI_A0_RXBuffer,g_ucUSCI_A0_RXBufferIndex); ...

C - Losing pointee struct values

**Updated. Sorry to those whose answers no longer make sense. So I figured out that no matter what I put on the line after Data_pair_node, after it executes, thats when the thing is reset! WTH? : int insert(Table *t, const char *key, const char *val){ int dest_bucket_index; Table *table = t; Hash_bucket *dest_bucket = NULL; Data_pa...

Functions and pointer to pointers

I have been trying to create a pointer variable in the called function and somehow pass the value pointed by it to the main function. I wrote a few sample programs but it i still seem to be missing something out. and the challenge was to achieve this using pointers to pointers to pointers. Here is the code that I wrote and tested. I thin...

C: Which is faster, accessing global variable or passing a pointer to the function

I am currently rewriting one of my programs. It has a heavily recursive function which solves peg-solitaire: int solve(int draw){ if(finished()) return true; //loop over every possible move (about 76 long long values) //do a move (access the board, which is a long long value) if(solve(int draw + 1)) return true; retu...

How do I print the value of a parameter when the type is not known in C?

How do I know what a particular address pointed by my pointer contains? I want to print the content in this address location? What should I add as a placeholder? ...

Assigning an address to a struct pointer array member in C.

Having considerable trouble with some pointer arithmatic. I think I get the concepts (pointer variables point to a memory address, normal variables point to data) but I believe my problem is with the syntax (*, &, (*), *(), etc.) What I want to do is build dynamic arrays of a custom struct (i.e. arrays of pointers to heap structs), and ...

Basic Objective-C Pointer Question

#import <Foundation/Foundation.h> BOOL areIntsDifferent( int thing1, int thing2 ) { if (thing1 == thing2) { return (NO); } else { return (YES); } } NSString *boolString (BOOL yesNo) { if (yesNo == NO) { return( @"NO" ); } else { return( @"YES" ); } } int main (int argc, const cha...

Basic Objective-C Pointer Question

Possible Duplicate: Basic Objective-C Pointer Question #import <Foundation/Foundation.h> BOOL areIntsDifferent( int thing1, int thing2 ) { if (thing1 == thing2) { return (NO); } else { return (YES); } } NSString *boolString (BOOL yesNo) { if (yesNo == NO) { return( @"NO" ); } else { return( @"YES" ); } } int m...