how to create an array for 15000 integers?

D

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"
 
W

wahaha

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 дµÀ£º
"
 
C

Christopher Benson-Manica

wahaha said:
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.
 
K

Keith Thompson

wahaha said:
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
 
B

Bill Reid

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

David T. Ashley

David said:
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.
 
J

jacob navia

David said:
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.
 
R

Richard Bos

jacob navia said:
David said:
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
 
J

jacob navia

Richard said:
David said:
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
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.




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?
 
C

CBFalconer

jacob said:
Richard Bos wrote:
.... snip ...

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

jacob navia

CBFalconer said:
... snip ...



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
 
R

Richard Heathfield

jacob navia said:
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.
 
J

jacob navia

Richard said:
jacob navia said:




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

David T. Ashley

jacob navia said:
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).

???
 
C

Coos Haak

Op Thu, 14 Dec 2006 11:52:19 -0500 schreef David T. Ashley:
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.
 
J

jacob navia

David T. Ashley a écrit :
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 :)
 
S

Simon Biber

jacob said:
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.
 
J

jacob navia

Simon Biber a écrit :
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
 
C

CBFalconer

jacob said:
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)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top