LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C problem! (https://www.linuxquestions.org/questions/programming-9/c-problem-20706/)

wwnn1 05-11-2002 01:34 AM

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

something like this:

char * ptr = 0x80000000;

Thanks in advance!

coolguy18087 05-11-2002 04:02 AM

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

wwnn1 05-11-2002 05:46 AM

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:
segment:offset (eg: 8000:0000);

what I want to do is:
assign the memory address, in the form of "segment:offset",
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!

Hano 05-11-2002 07:42 AM

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

coolguy18087 05-11-2002 12:33 PM

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.

Hano 05-11-2002 01:02 PM

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

coolguy18087 05-11-2002 03:13 PM

I have heard that comment before :cool:

wwnn1 05-12-2002 02:34 AM

Thanks!
 
Thanks all of you!

I think I have get what I need!


All times are GMT -5. The time now is 09:29 PM.