X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=L3AmZqzqqznntMxs Tu84c0/+ZFHiKmXVtEOeieAnL1Wi1UnBngq0hzDgz2YKehJJWJP5hiDO8TO/8zoY d+KA4l/E8Um024iI7/xs/NzF0/0bShHb6sI3k7BHUonCRdDZlNRSU/e8ff6nI08G aIyCC+kuZ+K898Wex5nEL70YVD8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=ZfVmfo6YznvLdk8Qh0Ms7K 3nDb0=; b=Uon2yxByXVtoSJ1aC6LZFh/gQ5Pv6V2Hya341ZVqCs/8CvpzoFtu6R W4+7+XFZfbGM8SKgtOU4nOH91oRwAWxphgeU+Kkg89KjpvRcypagcYNTgGIT4llK cn7M4PTDIbAS5mvX67IypeeLhVixgC326yPZJclaUXK2wSaNAMZpE= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=ASBESTOS_BODY,AWL,BAYES_40,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 spammy=20199, charles, Charles, onlist X-HELO: smtp-out-so.shaw.ca Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca Subject: Re: My C arrays are too large To: cygwin AT cygwin DOT com References: <87ftl0jb1i DOT fsf AT Rainer DOT invalid> From: Brian Inglis Openpgp: preference=signencrypt Message-ID: <709af282-4a75-0015-f20d-3316aaf406af@SystematicSw.ab.ca> Date: Thu, 19 Sep 2019 15:03:35 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes On 2019-09-18 14:35, Jose Isaias Cabrera wrote: > Joel Rees, on Wednesday, September 18, 2019 02:38 PM, wrote... >> 2019年9月14日(土) 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;} >>>>> compiles with gcc (no special options) but gives "Segmentation fault". >>>> You are creating an automatic variable that's larger than the default >>>> 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 some >>> warning, and also, it should never blow up with a "Segmentation fault". 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 = $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? Why do you want >> it allocated on the stack? > > I did not say automatically. I said that the compiler should provide some > warning about the allocation being larger than the default stack. And, it > should not result in a segmentation fault, but instead, the program should error > out with out of memory, or, at least, "memory allocation is larger than default > stack." Not just blow up. Arrays over about 4KB on the stack are not portable: developers either make them static local or global arrays for singletons, or malloc(3) dynamic arrays to allow multiple instances. As usual with C, gcc makes few default decisions about how compilations should be performed, as that is very dependent on the target runtime environment, leaving it to the developer to set the appropriate options for their application and target environment. Most development environments are heavy weight systems with GB of memory and disk, where the final target could be an embedded POS terminal, running some embedded Windows or Linux, or maybe just QNX or RTEMS. If you look at Cygwin gcc -v or -### you will see it was configured with --disable-libssp as default, leaving use of it to the developer's choice. If you want stack smashing protection (ssp) -fstack-protector look at all the gcc -fstack-... and -Wstack-... options: you may have to disable optimizations or selection of some options may be incompatible with some optimizations, set some warning levels depending on your environment, and add some libraries -lssp. Cygwin is a popular environment supporting development on Windows for all kinds of hardware e.g. FPGAs and SoCs, and systems e.g. BSD and Linux, and shares the same newlib libc/libm libraries used by RTEMS and other embedded systems, except OS-dependent functions which have to be emulated under Windows. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. -- 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