Menu

Stack overflow

horacius
2009-09-17
2012-09-26
  • horacius

    horacius - 2009-09-17

    Hi,

    i designed a C++ program in linux, which for not to give stack overflow uses:

    -fno-stack-limit

    and

    -fstack-check

    so it runs ok.

    But I want to port it to windows, I compiled with no problem in DEV-c++ and
    added this options manually to the linker, but I get stack overflow when I try
    to run the program

    Any ideas?

    Thanks

     
  • cpns

    cpns - 2009-09-17

    In Windows, a process is given ~2Mb stack by default. I do not know whether
    there is a linker option to change that - I doubt it, since to do so would
    affect other processes on the system by potentially hogging large amounts of
    memory.

    If your program overflows a stack that large 2Mb, I suggest that there is a
    problem with it. Either a bug, or bad design, or uncontrolled recursion, so
    perhaps just a large object that would be more appropriately allocated either
    statically or on the heap.

    I'd fix the problem rather than using kludgy head-in-the-sand fixes.

     
  • cpns

    cpns - 2009-09-17

    ... after further research on your behalf;

    My answer should probably have been "read the manual", but it is not
    always obvious which manual. In this case it is the GNU linker manual. The
    option you need is (follow the link).

    I still think that if you are significantly exceeding the default without good
    reason (or more importantly without understanding why), then you should really
    fix that in preference to this solution.

    Clifford

    http://sourceware.org/binutils/docs-2.16/ld/Options.html#index-
    _002d_002dstack-277

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.