array greater than 100

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

    array greater than 100

    Hi!
    when i define array[100][100] (any type)
    then compilator say that array is to large! ??

    i need at least 10.000 instead 100. This is for numeric methods in "C"

    any sugestion?
    thx
    Greetings
    P


  • Simon Biber

    #2
    Re: array greater than 100

    P.N. wrote:[color=blue]
    > Hi!
    > when i define array[100][100] (any type)
    > then compilator say that array is to large! ??
    >
    > i need at least 10.000 instead 100. This is for numeric methods in "C"
    >
    > any sugestion?[/color]

    Try something like this:

    #include <stdio.h>
    #include <stdlib.h>

    type (*foo)[100] = malloc(100 * sizeof *foo);
    if(foo == NULL)
    {
    fprintf(stderr, "Error allocating memory\n");
    exit(EXIT_FAILU RE);
    }
    else
    {
    /* use foo here, for example: */

    for(int i = 0; i < 100; i++)
    for(int j = 0; j < 100; j++)
    foo[i][j] = i + j;

    /* then free up the memory: */

    free(foo);
    }


    This defines 'foo' as a pointer to an array of 100 'type' objects.
    It then allocates 100 of these 100-element arrays.

    For some reasons that are off-topic on comp.lang.c, this method of
    allocation is more likely to work than directly specifying a 100x100 array.

    --
    Simon.

    Comment

    • Mark McIntyre

      #3
      Re: array greater than 100

      On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
      <el3ctron@klub. chip.pl> wrote:
      [color=blue]
      >Hi!
      >when i define array[100][100] (any type)
      >then compilator say that array is to large! ??[/color]

      you've hit a limitation of your compiler. The C standard doesn't
      require compilers to support objects that large.
      [color=blue]
      >i need at least 10.000 instead 100. This is for numeric methods in "C"
      >
      >any sugestion?[/color]

      Read up on malloc
      Mark McIntyre
      --
      "Debugging is twice as hard as writing the code in the first place.
      Therefore, if you write the code as cleverly as possible, you are,
      by definition, not smart enough to debug it."
      --Brian Kernighan

      Comment

      • Keith Thompson

        #4
        Re: array greater than 100

        Simon Biber <news@ralmin.cc > writes:[color=blue]
        > P.N. wrote:[color=green]
        >> Hi!
        >> when i define array[100][100] (any type)
        >> then compilator say that array is to large! ??
        >> i need at least 10.000 instead 100. This is for numeric methods in
        >> "C"
        >> any sugestion?[/color]
        >
        > Try something like this:
        >
        > #include <stdio.h>
        > #include <stdlib.h>
        >
        > type (*foo)[100] = malloc(100 * sizeof *foo);
        > if(foo == NULL)
        > {
        > fprintf(stderr, "Error allocating memory\n");
        > exit(EXIT_FAILU RE);
        > }
        > else
        > {
        > /* use foo here, for example: */
        >
        > for(int i = 0; i < 100; i++)
        > for(int j = 0; j < 100; j++)
        > foo[i][j] = i + j;
        >
        > /* then free up the memory: */
        >
        > free(foo);
        > }
        >
        >
        > This defines 'foo' as a pointer to an array of 100 'type' objects.[/color]

        No, "foo" is a pointer to an array of 100 pointers to "type" objects.
        [color=blue]
        > It then allocates 100 of these 100-element arrays.[/color]

        You didn't perform those allocations.

        I'm suprised that a declaration like:
        char array_obj[100][100]
        would cause a problem; that's only 10,000 bytes. But if you want a
        bigger array of larger elements, then yes, you're likely to need to
        use some other approach.

        See question 6.16 in the comp.lang.c FAQ, <http://www.c-faq.com/>.
        See also the rest of section 6, and the rest of the FAQ; it's all good
        stuff.

        (Simon, just citing the FAQ would have saved you a lot of time and
        avoided the risk of errors.)

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
        We must do something. This is something. Therefore, we must do this.

        Comment

        • Keith Thompson

          #5
          Re: array greater than 100

          Mark McIntyre <markmcintyre@s pamcop.net> writes:[color=blue]
          > On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
          > <el3ctron@klub. chip.pl> wrote:[color=green]
          >>when i define array[100][100] (any type)
          >>then compilator say that array is to large! ??[/color]
          >
          > you've hit a limitation of your compiler. The C standard doesn't
          > require compilers to support objects that large.[/color]

          10000 bytes? Yes, it does. (He said "any type", so I presume that
          includes char.)

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
          We must do something. This is something. Therefore, we must do this.

          Comment

          • Simon Biber

            #6
            Re: array greater than 100

            Keith Thompson wrote:[color=blue]
            > Simon Biber <news@ralmin.cc > writes:[color=green]
            >>type (*foo)[100] = malloc(100 * sizeof *foo);[/color][/color]
            [...][color=blue][color=green]
            >>This defines 'foo' as a pointer to an array of 100 'type' objects.[/color]
            >
            >
            > No, "foo" is a pointer to an array of 100 pointers to "type" objects.[/color]

            I don't think so! There are no pointers to "type" objects involved.

            $ cdecl explain 'int (*foo)[100]'
            declare foo as pointer to array 100 of int

            $ cat test.c
            #include <stdio.h>

            int main(void)
            {
            int (*foo)[100];

            printf("sizeof foo = %zu\n", sizeof foo);
            printf("sizeof *foo = %zu\n", sizeof *foo);

            return 0;
            }

            $ c99 test.c

            $ ./a.out
            sizeof foo = 8
            sizeof *foo = 400

            Here, foo is a pointer (8 bytes, 64 bits). It points to an array of size
            400 bytes, ie. 100 ints (each 4 bytes, 32 bits).

            My malloc call was:
            malloc(100 * sizeof *foo)

            This allocated 100 * sizeof *foo. Assuming 'type' was int, that's 40000
            bytes on my machine.

            --
            Simon.

            Comment

            • Keith Thompson

              #7
              Re: array greater than 100

              Simon Biber <news@ralmin.cc > writes:[color=blue]
              > Keith Thompson wrote:[color=green]
              >> Simon Biber <news@ralmin.cc > writes:[color=darkred]
              >>>type (*foo)[100] = malloc(100 * sizeof *foo);[/color][/color]
              > [...][color=green][color=darkred]
              >>>This defines 'foo' as a pointer to an array of 100 'type' objects.[/color]
              >> No, "foo" is a pointer to an array of 100 pointers to "type" objects.[/color]
              >
              > I don't think so! There are no pointers to "type" objects involved.[/color]

              D'oh! You're right.

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
              We must do something. This is something. Therefore, we must do this.

              Comment

              • santosh

                #8
                Re: array greater than 100

                Mark McIntyre wrote:[color=blue]
                > On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
                > <el3ctron@klub. chip.pl> wrote:
                >[color=green]
                > >Hi!
                > >when i define array[100][100] (any type)
                > >then compilator say that array is to large! ??[/color]
                >
                > you've hit a limitation of your compiler. The C standard doesn't
                > require compilers to support objects that large.[/color]

                Doesn't the standard garuntee that objects upto 64 kilobytes are
                garunteed to be supported?

                Comment

                • Jordan Abel

                  #9
                  Re: array greater than 100

                  On 2006-03-19, santosh <santosh.k83@gm ail.com> wrote:[color=blue]
                  > Doesn't the standard garuntee that objects upto 64 kilobytes are
                  > garunteed to be supported?[/color]

                  Not quite.

                  Comment

                  • P.N.

                    #10
                    Re: array greater than 100

                    > 10000 bytes? Yes, it does. (He said "any type", so I presume that[color=blue]
                    > includes char.)[/color]
                    sorry, of course no char, for numerical algorithm i do not need char type.


                    Comment

                    • Mark McIntyre

                      #11
                      Re: array greater than 100

                      On Sun, 19 Mar 2006 03:40:49 GMT, in comp.lang.c , Keith Thompson
                      <kst-u@mib.org> wrote:
                      [color=blue]
                      >Mark McIntyre <markmcintyre@s pamcop.net> writes:[color=green]
                      >> On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
                      >> <el3ctron@klub. chip.pl> wrote:[color=darkred]
                      >>>when i define array[100][100] (any type)
                      >>>then compilator say that array is to large! ??[/color]
                      >>
                      >> you've hit a limitation of your compiler. The C standard doesn't
                      >> require compilers to support objects that large.[/color]
                      >
                      >10000 bytes? Yes, it does. (He said "any type", so I presume that
                      >includes char.)[/color]

                      For C99 you're right:

                      5.2.4.1 trranslation limits
                      - 65534 bytes in an object. (in a hosted environment only).

                      However I recall that C89 was 32K, and I suspect the OP is using one
                      of those. Anyone got the old standard, to confirm?
                      Mark McIntyre
                      --
                      "Debugging is twice as hard as writing the code in the first place.
                      Therefore, if you write the code as cleverly as possible, you are,
                      by definition, not smart enough to debug it."
                      --Brian Kernighan

                      Comment

                      • P.N.

                        #12
                        Re: array greater than 100

                        I SEE imortant thing , that borland c++ 3.11 that i generally use, doesnt
                        permiss compile arrays up to max 40.
                        but borland c++ builder 6 permiss make arrays for example more than 1000
                        elemnts... and more dimensions.

                        of course that you later told is equal important.
                        thanks
                        P.N


                        Comment

                        • Vladimir S. Oka

                          #13
                          Re: array greater than 100

                          P.N. opined:
                          [color=blue]
                          > I SEE imortant thing , that borland c++ 3.11 that i generally use,
                          > doesnt permiss compile arrays up to max 40.
                          > but borland c++ builder 6 permiss make arrays for example more than
                          > 1000 elemnts... and more dimensions.[/color]

                          Limitations of your particular implementation are off-topic here.
                          [color=blue]
                          > of course that you later told is equal important.[/color]

                          Who knows what who said when you did not post any context?

                          Read:

                          <http://cfaj.freeshell. org/google/>
                          <http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

                          before posting again.

                          --
                          BR, Vladimir

                          Your true value depends entirely on what you are compared with.

                          Comment

                          • Robert Gamble

                            #14
                            Re: array greater than 100

                            Mark McIntyre wrote:[color=blue]
                            > On Sun, 19 Mar 2006 03:40:49 GMT, in comp.lang.c , Keith Thompson
                            > <kst-u@mib.org> wrote:
                            >[color=green]
                            > >Mark McIntyre <markmcintyre@s pamcop.net> writes:[color=darkred]
                            > >> On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
                            > >> <el3ctron@klub. chip.pl> wrote:
                            > >>>when i define array[100][100] (any type)
                            > >>>then compilator say that array is to large! ??
                            > >>
                            > >> you've hit a limitation of your compiler. The C standard doesn't
                            > >> require compilers to support objects that large.[/color]
                            > >
                            > >10000 bytes? Yes, it does. (He said "any type", so I presume that
                            > >includes char.)[/color]
                            >
                            > For C99 you're right:
                            >
                            > 5.2.4.1 trranslation limits
                            > - 65534 bytes in an object. (in a hosted environment only).
                            >
                            > However I recall that C89 was 32K, and I suspect the OP is using one
                            > of those. Anyone got the old standard, to confirm?[/color]

                            The limit for C89 was indeed 32K (actually 32,767 bytes, one byte less
                            than 32K) but this should still be enough for the OP to create an
                            object of 10000 chars.

                            Robert Gamble

                            Comment

                            • Keith Thompson

                              #15
                              Re: array greater than 100

                              Jordan Abel <random832@gmai l.com> writes:[color=blue]
                              > On 2006-03-19, santosh <santosh.k83@gm ail.com> wrote:[color=green]
                              >> Doesn't the standard garuntee that objects upto 64 kilobytes are
                              >> garunteed to be supported?[/color]
                              >
                              > Not quite.[/color]

                              Jordan, what exactly do you mean by "Not quite"? Are you referring to
                              the fact that the actual limit is 65535, 1 byte less than 64 kilobytes
                              (kibibytes if we're being pedantic)? Or do you mean that an
                              implementation is only required to accept a single program that
                              contains at least one instance of each of the limits specified in
                              5.2.4.1? Or did you mean something else?

                              Either way, posting "Not quite." with no further explanation is a
                              waste of time -- particularly mine. Presumably you know what what you
                              mean; take the time to tell the rest of us.

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                              We must do something. This is something. Therefore, we must do this.

                              Comment

                              Working...