how to create an array for 15000 integers?

Discussion in 'C Programming' started by David, Dec 13, 2006.

  1. David

    David Guest

    I need to do an array with around 15000 integers in it.
    I have declared it as unsigned letter[13000];
    But the compiler is saying that this is too much.
    How can I create an array for 15000 integers?

    I am using "Miracle C compiler".

    This is the error i am recieving:

    "c:\documents and settings\david\desktop\asdasdasdasdasdasdasdad22.c:
    line 6: too many locals declared
    'unsigned letter[15000]'
    aborting compile"
     
    David, Dec 13, 2006
    #1
    1. Advertising

  2. David

    wahaha Guest

    This will depend on how many memory your desktop has. Assume you have
    enough memory, you can write:

    unsigned int *letter;
    if ((letter = malloc(15000 *sizeof(int))) == NULL)
    return -1;


    "David дµÀ£º
    "
    > I need to do an array with around 15000 integers in it.
    > I have declared it as unsigned letter[13000];
    > But the compiler is saying that this is too much.
    > How can I create an array for 15000 integers?
    >
    > I am using "Miracle C compiler".
    >
    > This is the error i am recieving:
    >
    > "c:\documents and settings\david\desktop\asdasdasdasdasdasdasdad22.c:
    > line 6: too many locals declared
    > 'unsigned letter[15000]'
    > aborting compile"
     
    wahaha, Dec 13, 2006
    #2
    1. Advertising

  3. wahaha <> wrote:

    > This will depend on how many memory your desktop has. Assume you have
    > enough memory, you can write:


    A. Now you know.
    Q. Why is top-posting bad?

    > unsigned int *letter;
    > if ((letter = malloc(15000 *sizeof(int))) == NULL)

    if( (letter=malloc(15000*sizeof(*letter))) == NULL )
    > return -1;


    Not my first choice for error handling.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Dec 13, 2006
    #3
  4. "wahaha" <> writes:
    > This will depend on how many memory your desktop has. Assume you have
    > enough memory, you can write:
    >
    > unsigned int *letter;
    > if ((letter = malloc(15000 *sizeof(int))) == NULL)
    > return -1;


    letter is a pointer to unsigned int, but you use sizeof(int). Yes,
    they're guaranteed to be the same, but there's no point in depending
    on that. In fact, the preferred way to write that is:

    if ((letter = malloc(15000 * sizeof *letter)) == NULL)

    And what is the "return -1" supposed to accomplish? That makes sense
    only if the code is in a function that returns some integer (or at
    least arithmetic) type. If you're assuming the code is within main(),
    then (a) that's a bad assumption, and (b) returning -1 from main() is
    not portable.

    And please don't top-post. See the following:

    http://www.caliburn.nl/topposting.html
    http://www.cpax.org.uk/prg/writings/topposting.php

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Dec 13, 2006
    #4
  5. David

    Bill Reid Guest

    David <> wrote in message
    news:...

    > I need to do an array with around 15000 integers in it.
    > I have declared it as unsigned letter[13000];
    > But the compiler is saying that this is too much.
    > How can I create an array for 15000 integers?
    >
    > I am using "Miracle C compiler".
    >
    > This is the error i am recieving:
    >
    > "c:\documents and settings\david\desktop\asdasdasdasdasdasdasdad22.c:
    > line 6: too many locals declared
    > 'unsigned letter[15000]'
    > aborting compile"
    >

    Maybe try declaring it as a global array? Move it out of a
    function body and see what happens...

    ---
    William Ernest Reid
     
    Bill Reid, Dec 14, 2006
    #5
  6. "David" <> wrote in message
    news:...
    >I need to do an array with around 15000 integers in it.
    > I have declared it as unsigned letter[13000];
    > But the compiler is saying that this is too much.
    > How can I create an array for 15000 integers?
    >
    > I am using "Miracle C compiler".
    >
    > This is the error i am recieving:
    >
    > "c:\documents and settings\david\desktop\asdasdasdasdasdasdasdad22.c:
    > line 6: too many locals declared
    > 'unsigned letter[15000]'
    > aborting compile"


    Make it static or global.

    Or, dynamically allocate it.

    With a typical compiler, local variables are stored in what is called a
    "stack frame".

    http://en.wikipedia.org/wiki/Call_stack

    Typically, there are at least a couple of reasons why the size of the stack
    and each individual stack frame is limited. The most pressing reason is
    often that to retrieve and store values to the stack frame, machine
    instructions that are stack-relative are used. These instructions typically
    embed a stack-pointer relative offset into the instruction, and the
    instruction encoding imposes a limit on how big the offsets can be.
    Somewhere around 4,000 bytes (11 or 12 bits) strikes me as typical for a
    desktop machine. 15,000 integers is quite a large array.

    Most programmers think twice when something of storage class automatic that
    has more than a couple dozen elements.
     
    David T. Ashley, Dec 14, 2006
    #6
  7. David

    jacob navia Guest

    David wrote:
    > I need to do an array with around 15000 integers in it.
    > I have declared it as unsigned letter[13000];
    > But the compiler is saying that this is too much.
    > How can I create an array for 15000 integers?
    >
    > I am using "Miracle C compiler".
    >
    > This is the error i am recieving:
    >
    > "c:\documents and settings\david\desktop\asdasdasdasdasdasdasdad22.c:
    > line 6: too many locals declared
    > 'unsigned letter[15000]'
    > aborting compile"
    >


    You are using Miracl C, what is a DOS C ompiler. Under DOS you just
    can't do anything big like that, and specially the stack is a precious
    ressource to be used with utmost care.

    You have two possibilities:
    1) Go on use an obsolete compiler/OS and spend a lot of time
    programming around its limitations; This *could* have been
    OK in 1990, it is quite senseless now

    2) Use a 32 bit OS for your programming: Linux/windows, whatever.
     
    jacob navia, Dec 14, 2006
    #7
  8. David

    Richard Bos Guest

    jacob navia <> wrote:

    > David wrote:
    > > I need to do an array with around 15000 integers in it.
    > > I have declared it as unsigned letter[13000];
    > > But the compiler is saying that this is too much.
    > > How can I create an array for 15000 integers?
    > >
    > > I am using "Miracle C compiler".

    >
    > You are using Miracl C, what is a DOS C ompiler.


    _Which_ is a DOS compiler.

    > Under DOS you just can't do anything big like that,


    Bullshit. Under Miracle C you may not be able to do that, but that
    doesn't mean that there aren't any C implementations that do let you use
    this array. In fact, I'd be surprised if the one I used to use didn't.

    > 1) Go on use an obsolete compiler/OS and spend a lot of time
    > programming around its limitations; This *could* have been
    > OK in 1990, it is quite senseless now


    Tell that to the MS-DOS program that's still running the back-end of our
    A2 full-colour scanner.

    Richard
     
    Richard Bos, Dec 14, 2006
    #8
  9. David

    jacob navia Guest

    Richard Bos wrote:
    > jacob navia <> wrote:
    >
    >
    >>David wrote:
    >>
    >>>I need to do an array with around 15000 integers in it.
    >>>I have declared it as unsigned letter[13000];
    >>>But the compiler is saying that this is too much.
    >>>How can I create an array for 15000 integers?
    >>>
    >>>I am using "Miracle C compiler".

    >>
    >>You are using Miracl C, what is a DOS C ompiler.

    >
    >
    > _Which_ is a DOS compiler.


    Gosh I can't get that right...

    Thanks

    >
    >
    >>Under DOS you just can't do anything big like that,

    >
    >
    > Bullshit. Under Miracle C you may not be able to do that, but that
    > doesn't mean that there aren't any C implementations that do let you use
    > this array. In fact, I'd be surprised if the one I used to use didn't.
    >
    >
    >>1) Go on use an obsolete compiler/OS and spend a lot of time
    >> programming around its limitations; This *could* have been
    >> OK in 1990, it is quite senseless now

    >
    >
    > Tell that to the MS-DOS program that's still running the back-end of our
    > A2 full-colour scanner.


    USING MS-DOS programs, and even developing embedded software in MSDOS
    is OK. But LEARNING C with MSDOS?
     
    jacob navia, Dec 14, 2006
    #9
  10. jacob navia said:

    <snip>

    > USING MS-DOS programs, and even developing embedded software in MSDOS
    > is OK. But LEARNING C with MSDOS?


    Sure, why not?

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Dec 14, 2006
    #10
  11. David

    CBFalconer Guest

    jacob navia wrote:
    > Richard Bos wrote:
    >

    .... snip ...
    >>
    >> Tell that to the MS-DOS program that's still running the back-end
    >> of our A2 full-colour scanner.

    >
    > USING MS-DOS programs, and even developing embedded software in
    > MSDOS is OK. But LEARNING C with MSDOS?


    This is more likely to produce good habits, assuming an appropriate
    C compiler system, than using a non-standard systems which
    promulgates various non-portable extensions, and doesn't provide an
    easy and obvious way to inhibit all of them. In particular the
    DJGPP system will do just fine under DOS.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Dec 14, 2006
    #11
  12. David

    jacob navia Guest

    CBFalconer wrote:
    > jacob navia wrote:
    >
    >>Richard Bos wrote:
    >>

    >
    > ... snip ...
    >
    >>>Tell that to the MS-DOS program that's still running the back-end
    >>>of our A2 full-colour scanner.

    >>
    >>USING MS-DOS programs, and even developing embedded software in
    >>MSDOS is OK. But LEARNING C with MSDOS?

    >
    >
    > This is more likely to produce good habits, assuming an appropriate
    > C compiler system, than using a non-standard systems which
    > promulgates various non-portable extensions, and doesn't provide an
    > easy and obvious way to inhibit all of them. In particular the
    > DJGPP system will do just fine under DOS.
    >


    Mmmm... grasping the difference between the tiny/compact/medium/large
    "memory models", making the difference between near and far pointers,
    all that aren't any extensions of course.

    Yeah, of course
     
    jacob navia, Dec 14, 2006
    #12
  13. jacob navia said:

    > CBFalconer wrote:
    >> jacob navia wrote:
    >>
    >>>Richard Bos wrote:
    >>>

    >>
    >> ... snip ...
    >>
    >>>>Tell that to the MS-DOS program that's still running the back-end
    >>>>of our A2 full-colour scanner.
    >>>
    >>>USING MS-DOS programs, and even developing embedded software in
    >>>MSDOS is OK. But LEARNING C with MSDOS?

    >>
    >>
    >> This is more likely to produce good habits, assuming an appropriate
    >> C compiler system, than using a non-standard systems which
    >> promulgates various non-portable extensions, and doesn't provide an
    >> easy and obvious way to inhibit all of them. In particular the
    >> DJGPP system will do just fine under DOS.
    >>

    >
    > Mmmm... grasping the difference between the tiny/compact/medium/large
    > "memory models",


    Why would you need to do that just to learn C? The language knows nothing of
    such things.

    > making the difference between near and far pointers,


    Why would you need to do that just to learn C? The language knows nothing of
    such things.


    > all that aren't any extensions of course.
    >
    > Yeah, of course


    Yes, of course. Any conforming C implementation, plus a reasonable source
    editor, will do. Who cares what platform it's on? DOS is fine for such a
    purpose.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Dec 14, 2006
    #13
  14. David

    jacob navia Guest

    Richard Heathfield wrote:
    > jacob navia said:
    >
    >
    >>CBFalconer wrote:
    >>
    >>>jacob navia wrote:
    >>>
    >>>
    >>>>Richard Bos wrote:
    >>>>
    >>>
    >>>... snip ...
    >>>
    >>>
    >>>>>Tell that to the MS-DOS program that's still running the back-end
    >>>>>of our A2 full-colour scanner.
    >>>>
    >>>>USING MS-DOS programs, and even developing embedded software in
    >>>>MSDOS is OK. But LEARNING C with MSDOS?
    >>>
    >>>
    >>>This is more likely to produce good habits, assuming an appropriate
    >>>C compiler system, than using a non-standard systems which
    >>>promulgates various non-portable extensions, and doesn't provide an
    >>>easy and obvious way to inhibit all of them. In particular the
    >>>DJGPP system will do just fine under DOS.
    >>>

    >>
    >>Mmmm... grasping the difference between the tiny/compact/medium/large
    >>"memory models",

    >
    >
    > Why would you need to do that just to learn C? The language knows nothing of
    > such things.
    >


    You can't program on DOS without knowing those things.
    Apparently you have forgotten how it was, or never used it.
    I do remember how it was...

    >
    >>making the difference between near and far pointers,

    >
    >
    > Why would you need to do that just to learn C? The language knows nothing of
    > such things.
    >


    Impossible to avoid them if you program under DOS.
     
    jacob navia, Dec 14, 2006
    #14
  15. "jacob navia" <> wrote in message
    news:458178cd$0$5071$...
    >
    > You can't program on DOS without knowing those things.
    > Apparently you have forgotten how it was, or never used it.
    > I do remember how it was...


    10 or more years ago that definitely was the case (tiny, compact, large,
    huge, etc. memory models), but now with a modern machine under Windows isn't
    the notion of memory model all gone?

    I use Visual C++, and I don't remember a memory model setting (these days).

    ???
     
    David T. Ashley, Dec 14, 2006
    #15
  16. David

    Coos Haak Guest

    Op Thu, 14 Dec 2006 11:52:19 -0500 schreef David T. Ashley:

    > "jacob navia" <> wrote in message
    > news:458178cd$0$5071$...
    >>
    >> You can't program on DOS without knowing those things.
    >> Apparently you have forgotten how it was, or never used it.
    >> I do remember how it was...

    >
    > 10 or more years ago that definitely was the case (tiny, compact, large,
    > huge, etc. memory models), but now with a modern machine under Windows isn't
    > the notion of memory model all gone?
    >
    > I use Visual C++, and I don't remember a memory model setting (these days).
    >
    > ???


    Windows (32 bit) isn't DOS (16 bit), and the models here mentions matter.
    --
    Coos
     
    Coos Haak, Dec 14, 2006
    #16
  17. David

    jacob navia Guest

    David T. Ashley a écrit :
    > "jacob navia" <> wrote in message
    > news:458178cd$0$5071$...
    >
    >>You can't program on DOS without knowing those things.
    >>Apparently you have forgotten how it was, or never used it.
    >>I do remember how it was...

    >
    >
    > 10 or more years ago that definitely was the case (tiny, compact, large,
    > huge, etc. memory models), but now with a modern machine under Windows isn't
    > the notion of memory model all gone?
    >
    > I use Visual C++, and I don't remember a memory model setting (these days).
    >
    > ???
    >
    >
    >


    There isn't any more. For beginners this is better since
    all the complexities of 3 types of pointers are gone.

    Actually, for non-beginners too :)
     
    jacob navia, Dec 14, 2006
    #17
  18. David

    Simon Biber Guest

    jacob navia wrote:
    > CBFalconer wrote:
    >> This is more likely to produce good habits, assuming an appropriate
    >> C compiler system, than using a non-standard systems which
    >> promulgates various non-portable extensions, and doesn't provide an
    >> easy and obvious way to inhibit all of them. In particular the
    >> DJGPP system will do just fine under DOS.
    >>

    >
    > Mmmm... grasping the difference between the tiny/compact/medium/large
    > "memory models", making the difference between near and far pointers,
    > all that aren't any extensions of course.
    >
    > Yeah, of course


    If you use the system that Chuck recommended under DOS, DJGPP, then you
    won't be dealing with any tiny/compact/medium/large "memory models" or
    any different types of pointers. DJGPP programs run in a 32-bit
    environment using the go32 DOS extender.

    --
    Simon.
     
    Simon Biber, Dec 14, 2006
    #18
  19. David

    jacob navia Guest

    Simon Biber a écrit :
    > jacob navia wrote:
    >
    >> CBFalconer wrote:
    >>
    >>> This is more likely to produce good habits, assuming an appropriate
    >>> C compiler system, than using a non-standard systems which
    >>> promulgates various non-portable extensions, and doesn't provide an
    >>> easy and obvious way to inhibit all of them. In particular the
    >>> DJGPP system will do just fine under DOS.
    >>>

    >>
    >> Mmmm... grasping the difference between the tiny/compact/medium/large
    >> "memory models", making the difference between near and far pointers,
    >> all that aren't any extensions of course.
    >>
    >> Yeah, of course

    >
    >
    > If you use the system that Chuck recommended under DOS, DJGPP, then you
    > won't be dealing with any tiny/compact/medium/large "memory models" or
    > any different types of pointers. DJGPP programs run in a 32-bit
    > environment using the go32 DOS extender.
    >

    Right. You agree then with me that MSDOS is not really for learning,
    what I was saying.

    DJGPP is NOT dos, since, as you point out,

    > DJGPP programs run in a 32-bit environment using the go32 DOS
    > extender


    This is not the case of Miracl C, the subject of this thread.

    jacob
     
    jacob navia, Dec 14, 2006
    #19
  20. David

    CBFalconer Guest

    jacob navia wrote:
    > CBFalconer wrote:
    >> jacob navia wrote:
    >>> Richard Bos wrote:
    >>>

    >> ... snip ...
    >>>
    >>>> Tell that to the MS-DOS program that's still running the back-end
    >>>> of our A2 full-colour scanner.
    >>>
    >>> USING MS-DOS programs, and even developing embedded software in
    >>> MSDOS is OK. But LEARNING C with MSDOS?

    >>
    >> This is more likely to produce good habits, assuming an appropriate
    >> C compiler system, than using a non-standard systems which
    >> promulgates various non-portable extensions, and doesn't provide an
    >> easy and obvious way to inhibit all of them. In particular the
    >> DJGPP system will do just fine under DOS.

    >
    > Mmmm... grasping the difference between the tiny/compact/medium/large
    > "memory models", making the difference between near and far pointers,
    > all that aren't any extensions of course.


    What memory models? What 'near' and 'far' pointers? Those are
    non-standard, and don't appear in DJGPP. You are obviously
    unfamiliar with what 'standard C' implies. My default compile time
    flags under DJGPP/gcc are:

    -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal -gstabs+
    -O1

    and I have a high expectation of portability.

    (Richard Heathfield goes further)

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Dec 15, 2006
    #20
    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. Replies:
    9
    Views:
    7,989
    Ralf Hildebrandt
    Jan 19, 2005
  2. Replies:
    12
    Views:
    14,516
    Lee Ryman
    Apr 26, 2005
  3. Replies:
    8
    Views:
    808
    Oliver Wong
    Jan 27, 2006
  4. Royan
    Replies:
    32
    Views:
    995
  5. Rob Meade

    Array Integers vs Array Variables

    Rob Meade, Feb 8, 2004, in forum: ASP General
    Replies:
    16
    Views:
    248
    Roland Hall
    Feb 8, 2004
Loading...

Share This Page