473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Mar 18 '06 #1
18 2069
P.N. wrote:
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?


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_FAILURE);
}
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.
Mar 18 '06 #2
On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
<el******@klub.chip.pl> wrote:
Hi!
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.
i need at least 10.000 instead 100. This is for numeric methods in "C"

any sugestion?


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
Mar 18 '06 #3
Simon Biber <ne**@ralmin.cc> writes:
P.N. wrote:
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?
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_FAILURE);
}
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.


No, "foo" is a pointer to an array of 100 pointers to "type" objects.
It then allocates 100 of these 100-element arrays.


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_Keith) ks***@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.
Mar 18 '06 #4
Mark McIntyre <ma**********@spamcop.net> writes:
On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
<el******@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.


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

--
Keith Thompson (The_Other_Keith) ks***@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.
Mar 19 '06 #5
Keith Thompson wrote:
Simon Biber <ne**@ralmin.cc> writes:
type (*foo)[100] = malloc(100 * sizeof *foo); [...]This defines 'foo' as a pointer to an array of 100 'type' objects.

No, "foo" is a pointer to an array of 100 pointers to "type" objects.


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.
Mar 19 '06 #6
Simon Biber <ne**@ralmin.cc> writes:
Keith Thompson wrote:
Simon Biber <ne**@ralmin.cc> writes:
type (*foo)[100] = malloc(100 * sizeof *foo); [...]This defines 'foo' as a pointer to an array of 100 'type' objects.

No, "foo" is a pointer to an array of 100 pointers to "type" objects.


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


D'oh! You're right.

--
Keith Thompson (The_Other_Keith) ks***@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.
Mar 19 '06 #7
Mark McIntyre wrote:
On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
<el******@klub.chip.pl> wrote:
Hi!
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.


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

Mar 19 '06 #8
On 2006-03-19, santosh <sa*********@gmail.com> wrote:
Doesn't the standard garuntee that objects upto 64 kilobytes are
garunteed to be supported?


Not quite.
Mar 19 '06 #9
> 10000 bytes? Yes, it does. (He said "any type", so I presume that
includes char.)

sorry, of course no char, for numerical algorithm i do not need char type.
Mar 19 '06 #10
On Sun, 19 Mar 2006 03:40:49 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
<el******@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.


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


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
Mar 19 '06 #11
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
Mar 19 '06 #12
P.N. opined:
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.
Limitations of your particular implementation are off-topic here.
of course that you later told is equal important.


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.

Mar 19 '06 #13
Mark McIntyre wrote:
On Sun, 19 Mar 2006 03:40:49 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On Sat, 18 Mar 2006 13:51:26 +0100, in comp.lang.c , "P.N."
<el******@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.


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


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?


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

Mar 19 '06 #14
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, santosh <sa*********@gmail.com> wrote:
Doesn't the standard garuntee that objects upto 64 kilobytes are
garunteed to be supported?


Not quite.


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_Keith) ks***@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.
Mar 19 '06 #15
On 2006-03-19, Keith Thompson <ks***@mib.org> wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, santosh <sa*********@gmail.com> wrote:
Doesn't the standard garuntee that objects upto 64 kilobytes are
garunteed to be supported?
Not quite.


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?


I meant the second. The belief that everything will be OK as long as he
doesn't allocate any single object over 65535 bytes is obviously
ridiculous, so I didn't feel the need to explain.

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.

Mar 19 '06 #16
On 19 Mar 2006 07:19:37 -0800, in comp.lang.c , "Robert Gamble"
<rg*******@gmail.com> wrote:
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.


He wanted 10,000 floats (he clarified that later).
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
Mar 19 '06 #17
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, Keith Thompson <ks***@mib.org> wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, santosh <sa*********@gmail.com> wrote:
Doesn't the standard garuntee that objects upto 64 kilobytes are
garunteed to be supported?

Not quite.


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?


I meant the second. The belief that everything will be OK as long as he
doesn't allocate any single object over 65535 bytes is obviously
ridiculous, so I didn't feel the need to explain.


Since your comment was addressed to someone who obviously didn't know
that, clarity was particularly important.
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_Keith) ks***@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.
Mar 19 '06 #18
On 2006-03-19, Keith Thompson <ks***@mib.org> wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, Keith Thompson <ks***@mib.org> wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-19, santosh <sa*********@gmail.com> wrote:
> Doesn't the standard garuntee that objects upto 64 kilobytes are
> garunteed to be supported?

Not quite.

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?


I meant the second. The belief that everything will be OK as long as he
doesn't allocate any single object over 65535 bytes is obviously
ridiculous, so I didn't feel the need to explain.


Since your comment was addressed to someone who obviously didn't know
that, clarity was particularly important.


I shouldn't have to, if it's "obviously ridiculous". I interpreted the
statement I was replying to as indicative of a belief whose logical
extension was that you are guaranteed the ability to allocate _any
number_ of 65535-byte objects with no problem.
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.

Mar 19 '06 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
67
by: Ike Naar | last post by:
Hi, Asking your advice on the following subject: Suppose I want to find out whether a given pointer (say, p) of type *T points to an element of a given array (say, a) of type T. A way to...
46
by: RoSsIaCrIiLoIA | last post by:
Write a function that gets an array of unsigned int fill it with random values all differents, and sorts it. It should be faster than qsort too. Do you like my solution? _______________________...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
1
by: Kondapanaidu | last post by:
Hi, What is the logic to compare Values. First array={5,5,6,7}; Second array={5,3,3,2}; Explanation: 1.First array first element is greater than the second array first element, No need to...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
2
by: wing ver ka gundam | last post by:
THanks~ this is the example and my quote are below Write a program in JAVA that allows the user to input 5 ints. The program will then output these five values in reverse order. The program will...
10
by: ALKASER266 | last post by:
Hey guyz I have a prac and I am beginner and I did this code> Is my code is complete and if is it not complete how i can complete it? and how i can arrange it more? How I can make my driver to...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.