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

Discussion in 'C Programming' started by Michael, Oct 8, 2003.

  1. Michael

    Michael Guest

    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
     
    Michael, Oct 8, 2003
    #1
    1. Advertising

  2. (Michael) wrote in
    news::

    > 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[];

    --
    - Mark ->
    --
     
    Mark A. Odell, Oct 8, 2003
    #2
    1. Advertising

  3. Michael

    CBFalconer Guest

    Michael wrote:
    >
    > 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.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Oct 8, 2003
    #3
  4. Michael

    Michael Guest

    CBFalconer <> wrote in message news:<>...
    > Michael wrote:
    > >
    > > 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.


    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
     
    Michael, Oct 9, 2003
    #4
  5. Michael

    CBFalconer Guest

    Michael wrote:
    > CBFalconer <> wrote:
    > > Michael wrote:
    > > >
    > > > 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.

    >
    > 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.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Oct 9, 2003
    #5
  6. "Michael" <> schrieb im Newsbeitrag
    news:...
    > CBFalconer <> wrote in message

    news:<>...
    > > Michael wrote:
    > > >
    > > > 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.

    >
    > 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
     
    Robert Stankowic, Oct 9, 2003
    #6
  7. Michael

    Tauno Voipio Guest

    "Michael" <> wrote in message
    news:...
    > 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
     
    Tauno Voipio, Oct 9, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanjay Meher
    Replies:
    4
    Views:
    428
    Jon A. Cruz
    Feb 8, 2004
  2. candide
    Replies:
    65
    Views:
    1,452
  3. John Koleszar

    address of static array element as address constant

    John Koleszar, Jul 7, 2008, in forum: C Programming
    Replies:
    7
    Views:
    646
    John Koleszar
    Jul 15, 2008
  4. Stanley Rice

    Address of array && address of pointer to array

    Stanley Rice, Sep 14, 2011, in forum: C Programming
    Replies:
    33
    Views:
    1,204
    Keith Thompson
    Sep 20, 2011
  5. hisan
    Replies:
    1
    Views:
    1,407
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page