开发者

Stack overflow error in C, before any step

开发者 https://www.devze.com 2023-03-10 20:27 出处:网络
When I try to debug my C program, and even before the compiler starts executing any line I get: \"Unhandled exception at 0x00468867 in HistsToFields.exe: 0xC00000FD: Stack overflow.\"

When I try to debug my C program, and even before the compiler starts executing any line I get: "Unhandled exception at 0x00468867 in HistsToFields.exe: 0xC00000FD: Stack overflow."

I have no clue on how to spot the problem since the program hasn't even started executing any line (or at least this is what I can see from the compiler debugging window). How can I tell what is causing the overflow if there isn't yet any line of my program executed? "The when the debugger breaks it points to a line in chkstk.asm"

I'm using Microsoft Visual Studio 2008 on a win7.

I set the Stack Reserve Size to 300000000

PS: the program used to execute fine before but on another machine.

I have a database (120000 x 60)in csv format, I nee开发者_如何学运维d to change it to space delimited. The program (which I didn't write myself) defines a structure of the output file:

`struct  OutputFileContents {
    char    Filename[LINE_LEN];
    char    Title[LINE_LEN];
    int NVar;
    char    VarName[MAX_NVAR][LINE_LEN];
    char    ZoneTitle[LINE_LEN];
    int     NI;
    int     NJ;
    int     NK;
    double  Datums[MAX_NVAR];
    double  Data[MAX_NVAR][MAX_NPOINT];`  

This last array "Data[][]" is what contains all the output. hence is the huge size. This array size "MAX_NPOINT" is set in a header source file in the project, and this header is used by several programs in the projects.

Thank you very much in advance. Ahmad.


First, IDE != compiler != debugger.

Second, and no matter why the debugger fails debugging the application - a dataset that huge, on the stack, is a serious design error. Fix that design error, and your debugger problem will go away.

As for why the debugger fails... no idea. Too little RAM installed? 32bit vs 64bit platform? Infinite recursion in constructing static variables? Can't really say without looking at things you haven't showed us, like source, specs of environment, etc.

Edit: In case the hint is missed: Global / static data objects are constructed before main() starts executing. An infinite (or just much-too-deep) recursion in those constructors can trigger a stack overflow. (I am assuming C++ instead of C as the error message you gave says "unhandled exception".)

Edit 2: You added that you have a "database" that you need to convert to space-delimited. Without seeing the rest of your code: Trying to do the whole conversion in one go in memory isn't a good idea. Read a record, convert it, write it. Repeat. If you need stuff like "longest record" to determine the output format, iterate over the input once read-only for finding the output sizes, then iterate again doing the actual conversion.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号