LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2002, 01:34 AM   #1
wwnn1
Member
 
Registered: Apr 2002
Location: PRC
Posts: 32

Rep: Reputation: 15
Unhappy C problem!


How can I assign a memory address to pointer directly under gcc?

something like this:

char * ptr = 0x80000000;

Thanks in advance!
 
Old 05-11-2002, 04:02 AM   #2
coolguy18087
Member
 
Registered: Mar 2002
Posts: 30

Rep: Reputation: 15
I am not quite sure I understand what you are asking for. A pointer IS a memory address. But if you meant how can you point to a word address then I think you would need to do a int * ptr, since an int is 4 bytes, on the other hand a char is only 1 byte..... I am not sure if this even relevant to what you were looking for ...

Shiva
 
Old 05-11-2002, 05:46 AM   #3
wwnn1
Member
 
Registered: Apr 2002
Location: PRC
Posts: 32

Original Poster
Rep: Reputation: 15
thanks Shiva!


Maybe I do not let you understand clearly what I mean.

now, I retell the question below:

it does not matter the pointer's type is "int","char" or other types.

for example:
/*** define an array ***/
int str[10];

after that, we only know there is an array in the memory,
its name is "str",
but, we don't know clearly what its memory address is.
we can only access it by using symbol "str".

we know that,in memory the unit is arranged like this:
segmentffset (eg: 8000:0000);

what I want to do is:
assign the memory address, in the form of "segmentffset",
to a pointer directly.

maybe like this: pointer = 8000:0000;

my English is weak.
maybe I still don't tell you clearly what I mean!
I am sorry!
 
Old 05-11-2002, 07:42 AM   #4
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Rep: Reputation: 30
in old computers, you could access directly from processes memory regions assigned to devices, like video; screen colors, resolution, or sound, etc. (that was the case for my old atari 800 xl) In the actual paradigm on modern layered device management (also linux) when you run your program, the kernel assigns it a memory region only for that process. this region is called in the literature as heap . In this paradigm, the kernel takes care of handling direclty devide memory through API calls , of course, pointer are memory regions, but just mapped onto the heap.

Hano

Last edited by Hano; 05-11-2002 at 07:43 AM.
 
Old 05-11-2002, 12:33 PM   #5
coolguy18087
Member
 
Registered: Mar 2002
Posts: 30

Rep: Reputation: 15
Hano is right!

The OS is in charge of actually assigning physical address. You can look to see what address is being assinged to your array by doing &str or something similar. But even that in reality it is a virtual address; now if you actually know the entire computer architecture of your system -- i.e what is the page size, the cache size (including cache associativity and similar other factors) then you can actually do a conversion. Also, where the data segment or text segment begins is completely up to the OS. I am not sure why you are trying to do this -- this is one sure way that your program is not compatible even within similar architectures.

I beg to differ when you say an int* or char* doesn't make any difference while creating an array. IT DOES, b/c when you do str++, in int* you will be jumping 4 bytes, in char* you will be jumping 1 byte.
 
Old 05-11-2002, 01:02 PM   #6
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Rep: Reputation: 30
If you want to handle video to, say , draw things on screens, you have to learn to use a API library like Svgalib, or, for making 3D graphics, openGL its great. Remember that for handling a device, there a thousands of APIs that can do this, the one you should use depends on your system (linux) and taste. you can search them in google

may Shiva be with you

Hano
 
Old 05-11-2002, 03:13 PM   #7
coolguy18087
Member
 
Registered: Mar 2002
Posts: 30

Rep: Reputation: 15
Wink

I have heard that comment before
 
Old 05-12-2002, 02:34 AM   #8
wwnn1
Member
 
Registered: Apr 2002
Location: PRC
Posts: 32

Original Poster
Rep: Reputation: 15
Wink Thanks!

Thanks all of you!

I think I have get what I need!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration