From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24316 invoked by alias); 16 Jun 2004 23:45:04 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 24300 invoked from network); 16 Jun 2004 23:45:03 -0000 Received: from unknown (HELO masquerade.micron.com) (137.201.242.130) by sourceware.org with SMTP; 16 Jun 2004 23:45:03 -0000 Received: from mail-srv2.micron.com (localhost [127.0.0.1]) by masquerade.micron.com (8.12.9/8.12.2) with ESMTP id i5GNjB8l013343 for ; Wed, 16 Jun 2004 17:45:11 -0600 (MDT) Received: from ntxboimbx07.micron.com (ntxboimbx07.micron.com [137.201.80.94]) by mail-srv2.micron.com (8.12.9/8.12.2) with ESMTP id i5GNjAgA013339; Wed, 16 Jun 2004 17:45:10 -0600 (MDT) From: lrtaylor@micron.com content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: gcc array size limitation problem Date: Wed, 16 Jun 2004 23:45:00 -0000 Message-ID: <363801FFD7B74240A329CEC3F7FE4CC40215DB32@ntxboimbx07.micron.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: To: , X-Scanned-By: MIMEDefang 2.37 X-SW-Source: 2004-06/txt/msg00169.txt.bz2 You have to remember that integers are four bytes long, so you're actually trying to allocate an array of 4 * 2^29 bytes =3D 2,147,483,648 bytes. Note that this is one more than the theoretical maximum of 2^31 - 1 =3D 2,147,483,647. So, this does not appear to be a bug in the compiler, but probably expected behavior on a 32 bit machine. Thanks, Lyle -----Original Message----- From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of fdeng Sent: Wednesday, June 16, 2004 5:47 PM To: gcc-help@gcc.gnu.org Cc: fdeng@ualberta.ca Subject: gcc array size limitation problem Hi all, I used malloc() to create a large array.=20 When array size m=3D2^28, no problem,=20 but when m=3D2^29, it failed and malloc() returned NULL. My code is as follows: B =3D (unsigned int *)malloc(m*sizeof(unsigned int)); I used gcc 3.2.2 and then tried gcc 3.4.0, all failed. I searched the archive and found a similar problem of g77=20 and its answer. However, it seems not for gcc. Any ideas? Thanks a lot, Fan The similar mail I found is attached below: /**********************************************=20 ignat wrote: > Using g77 (GNU project Fortran Compiler, v0.5.24) I have encountered a > problem of array size limitation. > I found out that size of an array is limited to 2^27 -1 =3D 134 217 728, > while integer itself can be 2^31 -1 =3D 2 147 483 647. > I actually need an array with 600 000 000 numbers. What can I do? I fixed this for the 3.1 release, basically by removing a check that I proved unnecessarily strict. So you could try out a recent snapshot of gcc/g77 (see our home page at http://gcc.gnu.org, entry "Snapshots" in the left column). However, one shouldn't use snapshot compilers for production work. Another option is to apply the following patch to a recent release (see entry "Releases" in the left column) and build that compiler. Hope this helps, --=20 Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290 Saturnushof 14, 3738 XG Maartensdijk, The Netherlands Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction) 2001-10-22 Toon Moene * com.c (ffecom_check_size_overflow_): Only check for TREE_OVERFLOW. *** com.c.orig Fri Oct 19 14:59:44 2001 --- com.c Sun Oct 21 14:17:15 2001 *************** ffecom_check_size_overflow_ (ffesymbol s *** 2267,2272 **** if ((tree_int_cst_sgn (TYPE_SIZE (type)) < 0) ! || (!dummy && (((TREE_INT_CST_HIGH (TYPE_SIZE (type)) !=3D 0)) ! || TREE_OVERFLOW (TYPE_SIZE (type))))) { ffebad_start (FFEBAD_ARRAY_LARGE); --- 2267,2271 ---- if ((tree_int_cst_sgn (TYPE_SIZE (type)) < 0) ! || (!dummy && TREE_OVERFLOW (TYPE_SIZE (type)))) { ffebad_start (FFEBAD_ARRAY_LARGE);