How to keep the address of one array in my case?

M

Michael

Hi, all,

I want to keep the address of one static array in some place in order
to access the content of this array in other module. Which way should
I use?

I try it in this way: find one DRAM address, e.g. 0xff000000, and do
the following:

*(unsigned int *)0xff000000 = (unsigned int *)DataArray;

but it can not pass the compile process and there is a warning:
warning: assignment makes integer from pointer without a cast

I wonder if the compile can not know the exact address of DataArray at
this time and can not do this step. If so, does this mean that no way
to keep the address of DataArray in DRAM or Register?

Thank you very much for your suggestion!

Michael
 
M

Mark A. Odell

(e-mail address removed) (Michael) wrote in

I want to keep the address of one static array in some place in order
to access the content of this array in other module. Which way should
I use?

I try it in this way: find one DRAM address, e.g. 0xff000000, and do
the following:

*(unsigned int *)0xff000000 = (unsigned int *)DataArray;

This is not a good idea. If you want another module to access the address
of DataArray then either create an access function:

int GetDataArrayAddress(unsigned int *pDataArray, size_t *pSize)
{
int failures = !0;

if (pDataArray && pSize)
{
failures = 0;
pDataArray = DataArray;
*pSize = sizeof DataArray;
}

return failures;
}

and put its prototype in a header file as:

int GetDataArrayAddress(unsigned int *pDataArray, size_t *pSize);

and then include this header file in the module you wich to access the
array from. Or just put and extern of DataArray into the header file as:

extern unsigned int DataArray[];
 
C

CBFalconer

Michael said:
I want to keep the address of one static array in some place in
order to access the content of this array in other module. Which
way should I use?

That is silly. Either the static array is at file scope, and that
is done to prevent its access from outside the file, or it is in
function scope, and nothing outside that function can access it or
expose its address.

If at file scope, simply remove the static qualifier, and declare
it as extrn in the module accessing. If in function scope, have
the function return its address. However that way lie hungry
dragons, so not recommended.
 
M

Michael

CBFalconer said:
That is silly. Either the static array is at file scope, and that
is done to prevent its access from outside the file, or it is in
function scope, and nothing outside that function can access it or
expose its address.

If at file scope, simply remove the static qualifier, and declare
it as extrn in the module accessing. If in function scope, have
the function return its address. However that way lie hungry
dragons, so not recommended.

Hi,

Thank you for your reply.

In fact the other module I mentioned is independent of the first
program which has DataArray. You could regards these two programs as
two independent application programs. so the static and other skills
are not suitable for my case. Could you give me some info about this?

Thanks

Michael
 
C

CBFalconer

Michael said:
In fact the other module I mentioned is independent of the first
program which has DataArray. You could regards these two programs as
two independent application programs. so the static and other skills
are not suitable for my case. Could you give me some info about this?

You are looking for something outside the scope of the language.
Try a newsgroup dedicated to your OS and hardware.
 
R

Robert Stankowic

Michael said:
CBFalconer <[email protected]> wrote in message

Hi,

Thank you for your reply.

In fact the other module I mentioned is independent of the first
program which has DataArray. You could regards these two programs as
two independent application programs. so the static and other skills
are not suitable for my case. Could you give me some info about this?

It depends on what you want to do with DataArray. If you need it's contents
just once or only few times in the other program, there is a possibility
using standard C:
Write the content of DataArray to a temporary file and read the file in the
other application, probably using a time stamp or a sequence number to
syncronize between both applications.
Otherwise you will have to use system-specific extensions, which would bw OT
here. In this case better ask in a NG for your system/implementation

HTH
Robert
 
T

Tauno Voipio

Michael said:
Hi, all,

I want to keep the address of one static array in some place in order
to access the content of this array in other module. Which way should
I use?

I try it in this way: find one DRAM address, e.g. 0xff000000, and do
the following:

*(unsigned int *)0xff000000 = (unsigned int *)DataArray;

but it can not pass the compile process and there is a warning:
warning: assignment makes integer from pointer without a cast

I wonder if the compile can not know the exact address of DataArray at
this time and can not do this step. If so, does this mean that no way
to keep the address of DataArray in DRAM or Register?


This smells of inter-process shared memory. It is operating-system dependent
and has little common with the C language. Try again in an operating-system
oriented group (e.g. comp.os.linux.apps).

Tauno Voipio
tauno voipio @ iki fi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top