public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: My C arrays are too large
Date: Thu, 19 Sep 2019 21:58:00 -0000	[thread overview]
Message-ID: <709af282-4a75-0015-f20d-3316aaf406af@SystematicSw.ab.ca> (raw)
In-Reply-To: <VI1P195MB0765C387C43BC4417FAFD8E3DE8E0@VI1P195MB0765.EURP195.PROD.OUTLOOK.COM>

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<stdio.h>
>>>>> 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

  parent reply	other threads:[~2019-09-19 21:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 12:18 Blair, Charles E III
2019-09-13 12:37 ` Eliot Moss
2019-09-13 18:44 ` Achim Gratz
2019-09-13 18:50   ` Eliot Moss
2019-09-13 19:01   ` Jose Isaias Cabrera
2019-09-14  5:32     ` Lee
2019-09-18 19:09     ` Joel Rees
2019-09-18 20:40       ` Jose Isaias Cabrera
2019-09-18 20:46         ` Eliot Moss
2019-09-19  1:19         ` Joel Rees
2019-09-19 18:04           ` Jose Isaias Cabrera
2019-09-19 21:58         ` Brian Inglis [this message]
2019-09-13 13:44 my " Blair, Charles E III
2019-09-13 14:20 ` Eliot Moss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=709af282-4a75-0015-f20d-3316aaf406af@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).