473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Pointer to memory

How does on "point" a pointer at a specific memory address? I have a
program where I've malloc'd some memory and need to move around and
make changes. I know I can move a pointer in the malloc'd storage by
incrementing a pointer. However, in this malloc'd storage, I have
stored addresses of other locations and would like to "jump" from one
memory location to another based on what I find in certain memory
ranges. Don't worry, I've taken care of word aligning, etc. etc.

So to recap:
1. I have malloc'd storage
2. I have written blocks of data into this storage (I know it's there
because I can traverse the entire storage and output the information
alas, by incrementing the pointer)
3. I need to jump from run location to another based on some of the
data I've added.
Thanks,
Mark
Nov 13 '05 #1
2 1755
In article <ca**************************@posting.google.com >, MarkY wrote:
[cut]
So to recap:
1. I have malloc'd storage
2. I have written blocks of data into this storage (I know it's there
because I can traverse the entire storage and output the information
alas, by incrementing the pointer)
3. I need to jump from run location to another based on some of the
data I've added.

Is this very different from

thing = memoryarray[memoryarray[i]];

or

thing = memoryarray[(int) memoryarray[i]];

or possibly

thing = memoryarray[converttoindex(&memoryarray[i])];

(where converttoindex() returns an int computed from the data
pointed to by the argument) ?
You're allowed to do that, but you're responsible for making
sure you store the right things at the right places with the
right types.
--
Andreas Kähäri
Nov 13 '05 #2
Andreas Kahari <ak*******@freeshell.org> wrote in message news:<sl**********************@norge.freeshell.org >...
In article <ca**************************@posting.google.com >, MarkY wrote: <snip>
Is this very different from

thing = memoryarray[memoryarray[i]];

or

thing = memoryarray[(int) memoryarray[i]];

or possibly

thing = memoryarray[converttoindex(&memoryarray[i])];

(where converttoindex() returns an int computed from the data
pointed to by the argument) ?
You're allowed to do that, but you're responsible for making
sure you store the right things at the right places with the
right types.


Thanks Andreas. I was able to use a slightly modified version of Option 3.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
52
by: Douglas Garstang | last post by:
I can't believe I've been trying to work this out for hours now, and I can't believe I couldn't find someone asking for a similar solution in the newsgroups. No wonder I hate C so much, and every...
22
by: Christopher Benson-Manica | last post by:
Is adding 0 to a pointer to non-void that is equal to NULL legal? int *p=NULL; p+=0; -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
8
by: kathy | last post by:
If I have 2D array like: int **p; p = new int*; for(int i=0;i<10;i++) { p = new int; }
3
by: David Mathog | last post by:
This one is driving me slightly batty. The code in question is buried deep in somebody else's massive package but it boils down to this, two pointers are declared, the first is: char **resname...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
6
by: Mahendra | last post by:
I have two cases - 1. When I have a pointer A pointing to a heap memory - What happens when I dereference the pointer A using free(A). It deallocated the heap memory the pointer was pointing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.