Array at specific address

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    Array at specific address

    Hi I have an array of unsigned chars, like:
    MyArray[2048] = {0x00};

    For memory-mapping purposes I need to store this array at a specific address
    (0xFFFF1199)

    How do I declare this?

    I cant't do MyArray[2048] = {0x00} @ 0xFFFF1199 :-(

    I am using the gnu compiler.

    Best Regards
    Don


  • Joona I Palaste

    #2
    Re: Array at specific address

    Don <nono@spam.dk > scribbled the following:[color=blue]
    > Hi I have an array of unsigned chars, like:
    > MyArray[2048] = {0x00};[/color]
    [color=blue]
    > For memory-mapping purposes I need to store this array at a specific address
    > (0xFFFF1199)[/color]
    [color=blue]
    > How do I declare this?[/color]

    You can't. Not under ISO standard C. On some implementations , you can't
    declare it at all.
    [color=blue]
    > I cant't do MyArray[2048] = {0x00} @ 0xFFFF1199 :-([/color]

    No, you can't.
    [color=blue]
    > I am using the gnu compiler.[/color]

    It depends on more than your compiler. Some operating systems don't
    allow specific addresses at all, due to security reasons. What happens
    if some other process is already using that memory?
    Please ask in gnu.gcc.help or a system-specific newsgroup.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/

    Comment

    • Derk Gwen

      #3
      Re: Array at specific address

      "Don" <nono@spam.dk > wrote:
      # Hi I have an array of unsigned chars, like:
      # MyArray[2048] = {0x00};

      If it _has_ to be an array instead of (unsigned char*), many linkers allow you to
      specify the address of extern objects. You might try checking what your linker
      permits.

      --
      Derk Gwen http://derkgwen.250free.com/html/index.html
      You face forward, or you face the possibility of shock and damage.

      Comment

      • Kevin Easton

        #4
        Re: Array at specific address

        Derk Gwen <derkgwen@hotpo p.com> wrote:[color=blue]
        > "Don" <nono@spam.dk > wrote:
        > # Hi I have an array of unsigned chars, like:
        > # MyArray[2048] = {0x00};
        >
        > If it _has_ to be an array instead of (unsigned char*), many linkers allow you to
        > specify the address of extern objects. You might try checking what your linker
        > permits.[/color]

        You can do it without linker magic also:

        #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))

        - Kevin.

        Comment

        • Darrell Grainger

          #5
          Re: Array at specific address

          On Thu, 25 Sep 2003, Don wrote:
          [color=blue]
          > Hi I have an array of unsigned chars, like:
          > MyArray[2048] = {0x00};
          >
          > For memory-mapping purposes I need to store this array at a specific address
          > (0xFFFF1199)
          >
          > How do I declare this?
          >
          > I cant't do MyArray[2048] = {0x00} @ 0xFFFF1199 :-(
          >
          > I am using the gnu compiler.[/color]

          If possible, just use:

          unsigned char *MyArray = (unsigned char *)0xFFFF1199;

          and then use MyArray as if you declared it as an array. The only
          difference is that sizeof(MyArray) will not return 2048.

          If you have to have it as an array then check with a newsgroup that deals
          with your compiler. You can sometimes define a section of data to a linker
          section name (.text, .bss. data, etc.) and then instruct the linker to put
          that section at a specific memory location. This is highly dependent on
          your linker and completely off topic for comp.lang.c.

          --
          darrell at cs dot toronto dot edu
          or
          main(){int j=1234;char t[]=":@abcdefghijk lmnopqrstuvwxyz .\n",*i=
          "iqgbgxmdbjlgdv .lksrqek.n";cha r *strchr(const char *,int);while(
          *i){j+=strchr(t ,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}

          Comment

          • Mark McIntyre

            #6
            Re: Array at specific address

            On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton
            <kevin@-nospam-pcug.org.au> wrote:
            [color=blue]
            >Derk Gwen <derkgwen@hotpo p.com> wrote:[color=green]
            >> "Don" <nono@spam.dk > wrote:
            >> # Hi I have an array of unsigned chars, like:
            >> # MyArray[2048] = {0x00};
            >>
            >> If it _has_ to be an array instead of (unsigned char*), many linkers allow you to
            >> specify the address of extern objects. You might try checking what your linker
            >> permits.[/color]
            >
            >You can do it without linker magic also:
            >
            >#define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[/color]

            When I tried this on my DS9K, it said "moo" and printed out a recipe
            for making cow from hamburger.


            --
            Mark McIntyre
            CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
            CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>

            Comment

            • Martijn

              #7
              Re: Array at specific address

              >> #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[color=blue]
              >
              > When I tried this on my DS9K, it said "moo" and printed out a recipe
              > for making cow from hamburger.[/color]

              liar


              Comment

              • Micah Cowan

                #8
                Re: Array at specific address

                Joona I Palaste <palaste@cc.hel sinki.fi> writes:
                [color=blue]
                > Don <nono@spam.dk > scribbled the following:[color=green]
                > > Hi I have an array of unsigned chars, like:
                > > MyArray[2048] = {0x00};[/color]
                >[color=green]
                > > For memory-mapping purposes I need to store this array at a specific address
                > > (0xFFFF1199)[/color]
                >[color=green]
                > > How do I declare this?[/color]
                >
                > You can't. Not under ISO standard C. On some implementations , you can't
                > declare it at all.[/color]

                Of course you can.

                memcpy((void*)0 xFFFF1199, MyArray, sizeof MyArray);

                Now, whether or not this does what you want is
                implementation-defined, but you certainly can do it, if it's
                doable. The Standard specifically says so.

                -Micah

                Comment

                • Default User

                  #9
                  Re: Array at specific address

                  Martijn wrote:[color=blue]
                  >[color=green][color=darkred]
                  > >> #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[/color]
                  > >
                  > > When I tried this on my DS9K, it said "moo" and printed out a recipe
                  > > for making cow from hamburger.[/color]
                  >
                  > liar[/color]


                  It would be just like the DS9000 to print out a bogus recipe. That's the
                  kind of thing it likes to do.




                  Brian Rodenborn

                  Comment

                  • Micah Cowan

                    #10
                    Re: Array at specific address

                    Default User <first.last@com pany.com> writes:
                    [color=blue]
                    > Martijn wrote:[color=green]
                    > >[color=darkred]
                    > > >> #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))
                    > > >
                    > > > When I tried this on my DS9K, it said "moo" and printed out a recipe
                    > > > for making cow from hamburger.[/color]
                    > >
                    > > liar[/color]
                    >
                    >
                    > It would be just like the DS9000 to print out a bogus recipe. That's the
                    > kind of thing it likes to do.
                    >[/color]

                    Should be thankful it didn't launch nukes



                    -Micah

                    Comment

                    • Jack Klein

                      #11
                      Re: Array at specific address

                      On 25 Sep 2003 15:33:28 -0700, Micah Cowan <micah@cowan.na me> wrote in
                      comp.lang.c:
                      [color=blue]
                      > Joona I Palaste <palaste@cc.hel sinki.fi> writes:
                      >[color=green]
                      > > Don <nono@spam.dk > scribbled the following:[color=darkred]
                      > > > Hi I have an array of unsigned chars, like:
                      > > > MyArray[2048] = {0x00};[/color]
                      > >[color=darkred]
                      > > > For memory-mapping purposes I need to store this array at a specific address
                      > > > (0xFFFF1199)[/color]
                      > >[color=darkred]
                      > > > How do I declare this?[/color]
                      > >
                      > > You can't. Not under ISO standard C. On some implementations , you can't
                      > > declare it at all.[/color]
                      >
                      > Of course you can.
                      >
                      > memcpy((void*)0 xFFFF1199, MyArray, sizeof MyArray);
                      >
                      > Now, whether or not this does what you want is
                      > implementation-defined, but you certainly can do it, if it's
                      > doable. The Standard specifically says so.
                      >
                      > -Micah[/color]

                      Exactly how does this declare an array of 2048 unsigned characters at
                      all?

                      BTW, you're another one who could use a proper signature separator.

                      --
                      Jack Klein
                      Home: http://JK-Technology.Com
                      FAQs for
                      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                      alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

                      Comment

                      • James

                        #12
                        Re: Array at specific address

                        Hi,

                        To declare an array in C:
                        {
                        char temp[100] ;

                        }

                        Compiler must know its size. If the array is declared in a context the
                        compiler places it in stack and if a global it places it in heap.



                        Now how to place an array at a specified location.

                        I think a static array u can't place it.


                        With a pointer u can do it.

                        char * p = (char *) 1000 ;


                        Now u can use p like u use an array.

                        p [10] works



                        Hope this helps,



                        Regards,
                        James

                        Comment

                        • Kevin Easton

                          #13
                          Re: Array at specific address

                          Mark McIntyre <markmcintyre@s pamcop.net> wrote:[color=blue]
                          > On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton
                          > <kevin@-nospam-pcug.org.au> wrote:
                          >[color=green]
                          >>Derk Gwen <derkgwen@hotpo p.com> wrote:[color=darkred]
                          >>> "Don" <nono@spam.dk > wrote:
                          >>> # Hi I have an array of unsigned chars, like:
                          >>> # MyArray[2048] = {0x00};
                          >>>
                          >>> If it _has_ to be an array instead of (unsigned char*), many linkers allow you to
                          >>> specify the address of extern objects. You might try checking what your linker
                          >>> permits.[/color]
                          >>
                          >>You can do it without linker magic also:
                          >>
                          >>#define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[/color]
                          >
                          > When I tried this on my DS9K, it said "moo" and printed out a recipe
                          > for making cow from hamburger.[/color]

                          A legal preprocessor directive did all that? I think you need to get a
                          conforming implementation (I'm reliably informed that one exists for the
                          DS9000).

                          - Kevin.

                          Comment

                          • Mark McIntyre

                            #14
                            Re: Array at specific address

                            On Fri, 26 Sep 2003 00:00:56 +0200, in comp.lang.c , "Martijn"
                            <subscription-NOSPAM-101@hotNOFILTER mail.com> wrote:
                            [color=blue][color=green][color=darkred]
                            >>> #define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[/color]
                            >>
                            >> When I tried this on my DS9K, it said "moo" and printed out a recipe
                            >> for making cow from hamburger.[/color]
                            >
                            >liar[/color]

                            No, thats a greek musical instrument, beloved by muses the world over.
                            I do admit its often strung with cowgut though.

                            --
                            Mark McIntyre
                            CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                            CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>

                            Comment

                            • Mark McIntyre

                              #15
                              Re: Array at specific address

                              On Fri, 26 Sep 2003 10:32:04 GMT, in comp.lang.c , Kevin Easton
                              <kevin@-nospam-pcug.org.au> wrote:
                              [color=blue]
                              >Mark McIntyre <markmcintyre@s pamcop.net> wrote:[color=green]
                              >> On Thu, 25 Sep 2003 10:02:07 GMT, in comp.lang.c , Kevin Easton[color=darkred]
                              >>>
                              >>>#define MyArray (*(volatile unsigned char (*)[2048])(0xdeadbeef))[/color]
                              >>
                              >> When I tried this on my DS9K, it said "moo" and printed out a recipe
                              >> for making cow from hamburger.[/color]
                              >
                              >A legal preprocessor directive did all that?[/color]

                              The message appeared at runtime. The result of the directive is just a
                              tad implementation defined, I believe.
                              [color=blue]
                              >I think you need to get a
                              >conforming implementation (I'm reliably informed that one exists for the
                              >DS9000).[/color]

                              The one I have is as conforming as it gets, if somewhat
                              pathological...


                              --
                              Mark McIntyre
                              CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                              CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>

                              Comment

                              Working...