From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9956 invoked by alias); 18 Sep 2019 23:09:24 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 9943 invoked by uid 89); 18 Sep 2019 23:09:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=ASBESTOS_BODY,AWL,BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.1 spammy=up, 20199, suit, foot X-HELO: mail-wm1-f41.google.com Received: from mail-wm1-f41.google.com (HELO mail-wm1-f41.google.com) (209.85.128.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Sep 2019 23:09:22 +0000 Received: by mail-wm1-f41.google.com with SMTP id p7so2002173wmp.4 for ; Wed, 18 Sep 2019 16:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ijof0/wdoKGnCXtpSkXYkYojm2czojZK43pjgfDYjjU=; b=lPFB6VGZdkMbFSnd0LlgRhmlvB7v5+3eY74/FUp/U3icT5Qg8Pw5Qkhs45D0EgxOlf y59KDkTkBSj662jNYNiONUJIgZo7EU1FugZx/XVetgkGB3UjOAoxClNsxH1Xm6jgZvr4 krZoTTIAmdxoMhyqTrZ61O53GfAtShY/2dduvRbYISZ3QaiI3aQW4FE3RQvPvnuTON/N k8HKD5v6cGto6kpFF28W/5tQn88LIyvd/VffjpZFeESCwrZOskC197fA+txBWAetyKI5 a6HeZGfaAOBZ5jDzJTVNcMxlLUaXW/xcxJRr9IbOE5IAPrasbjGzLUJg3ud2L9p35eUi o+6Q== MIME-Version: 1.0 References: <87ftl0jb1i.fsf@Rainer.invalid> In-Reply-To: From: Joel Rees Date: Thu, 19 Sep 2019 01:19:00 -0000 Message-ID: Subject: Re: My C arrays are too large To: Jose Isaias Cabrera Cc: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00201.txt.bz2 I guess I should unpack things a bit, and I may sound argumentative, but my argument is not really with anyone on this list. 2019=E5=B9=B49=E6=9C=8819=E6=97=A5(=E6=9C=A8) 5:35 Jose Isaias Cabrera : > > Joel Rees, on Wednesday, September 18, 2019 02:38 PM, wrote... > > > > 2019=E5=B9=B49=E6=9C=8814=E6=97=A5(=E5=9C=9F) 3:50 Jose Isaias Cabrera,= on > > > > > > > > Achim Gratz, on Friday, September 13, 2019 02:39 PM, wrote... > > > > > > > > Blair, Charles E III writes: > > > > > My apologies for failing to reply on-list. I don't know how :( > > > > > > > > > > My machine is 64 bit, and I hope I installed the correct version = of > > > cygwin. > > > > > > > > > > This program: > > > > > > > > > > #include > > > > > int main(){char *a[50][8192]; > > > > > return 0;} > > > > > > /* programmatic example by Jose Isaias Cabrera // reformatting and annotation by Joel Rees */ #include int main( void ) { char *a[50][8192]; /* Note that variables declared here are default "auto" allocated. */ return 0; /* Note that some optimization settings might // entirely optimize the allocation out in recent compilers, // or optimize main() to just return 0 to the calling environment, // completely removing the allocation. */ } > > > > compiles with gcc (no special options) but gives "Segmentation > fault". > > > > > > > > You are creating an automatic variable that's larger than the defau= lt > > > > stack. You need to enlarge the stack, either during link time or > later > > > > e.g. via > > > > > > > > peflags -x0x800000 a.out > > > > > > This is great! Thanks. > > > > > > But, let's talk about this a bit... Shouldn't the compiler provide so= me > > > warning, > It would be nice, yes. > > and also, it should never blow up with a "Segmentation fault". > But we are discussing C, and, frankly, I'd prefer segementation faults to some of the possibilities that have been discussed by the engineering teams that work on C compilers. Ada, yes, the compiler is supposed to (mostly) prevent you from writing things that give segmentation faults. C, no. It's within the nature of the language itself. C is specifically designed to allow the programmer to shoot him/herself in the foot, and with good reason. Lately, some reasonable protection is provided, according to the engineering teams' consideration of what is reasonable, and there is a lot of argument about what level of protection is too much. > > I > > > believe there should be some type of Out Of Memory error, or something > like > > > it. But now just blow up. Anyone thinks like me? Just my 102 > Dominican > > > cents ($1 =3D $51 Dominican). :-) > > > > > > > Well, the behavior of the compiler itself is better discussed on the > > compiler's forums, although you may need your asbestos suit when you do > so. > > > > That said, why do you want this variable to be automatic? > As Eliot says, it might have been more clear if I had said "auto". Auto in C means local to the function in both visibility and duration, which essentially translates to allocation that looks like it's on a stack. > Why do you want > > it allocated on the stack? > Now, a good introductory software engineering course will usually encourage you to use local visibility and duration unless you have a good reason not to. But the larger a variable is, the more likely there is to be a good reason for declaring the variable to have different scope. Buffers, for instance, should persist between calls (static duration), and symbol tables should usually be visible to all functions that refer to them (extern visibility). All of that said, you are right to wonder at this behavior. Modern compilers inherit a lot of anti-optimal best worst practices from the days of sixteen-bit addresses. One of those is combining the flow-of-control stack with the parameter stack in an interleaved linked list of local allocations, enabling simple stack-smash attacks. Locating that overloaded stack in as small a corner of address space as possible is another, and it results in trouble anytime you allocate large things on the stack, with local visibility, local duration, thus, auto. (This practice is more in the operating system scope than in the compiler scope, but the libraries the compiler links in define the behavior and give the error messages.) Yeah, this is a favorite topic of mine, occupying a bit of space in my programming and computing related blogs. Non-optimal, but it is what you get: Either don't allocate large variables and structures on the stack, or use compiler or linker flags, or command line tools, to set the object to allocate a large stack. Or hope you get segment violations instead of silent errors. Joel Rees (Maybe I should blog this.) -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple