hot to solve error (0xc00000fd)

Hello,
I'm trying to split my main.cpp into several.cpp files. I'm using a single header file to contain all my definitions.
I am using multiple structs to organize my variables. this was working nicely in the original main.cpp. But when I moved the struck definitions to the new header file (in order to be used in multiple .cpp files) and declare a struct object in the main.cpp. this error (0xc00000fd) happens.

I have noticed that if I include a small part of the struct the problem doesn't happen. but of course, I need to include all of them. how to solve this problem.


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include "header.h"


using namespace std;
  int main()
{

    grid_point gp;
    
    U_left U_L;
    U_right U_R;
    Fluxes F_tilde;
    cell_center cell;
    
//some functions to be used like:
//read_geometry(&gp);
// calc_geometry(&gp,&cell);


    return 0;
}


here is the header file header.h :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED

#include <iostream>
#include<math.h>
#include<fstream>
#include <cmath>
#include <assert.h>
#define pi 3.14159
#define N 142           
#define M 48           

struct direction {
    float s[N][M]; //south
    float e[N][M]; //east
    float n[N][M]; //north
    float w[N][M]; //east
};

struct vector_element {
    float ele1[N][M];
    float ele2[N][M];
    float ele3[N][M];
    float ele4[N][M];
};

//grid points positions
 struct grid_point {
    float x[N+1][M+1];
    float y[N+1][M+1];
};


 struct cell_center{
    ///Geometric properties
    float X[N][M];
    float Y[N][M];
    float center[N][M];
    struct direction dx;
    struct direction dy;
    struct direction ds;
    struct direction nx;
    struct direction ny;
    float deltaS1[N][M];
    float deltaS2[N][M];
    float omega[N][M];
    float A[N][M];

    ///conservative vector elements for each cell
    struct vector_element U;

    struct vector_element U_new;
    ///Total Flux for each cell
    struct vector_element F_tilde_total;

    ///flow properties
    float rho[N][M]; //density
    float u[N][M];   //flow velocity in x direction
    float v[N][M];   //flow velocity in y direction
    float P[N][M];   //pressure
    float c[N][M];   //speed of sound
    float Ma[N][M];  //Mach number
    float H[N][M];   //enthalpy
    float dt[N][M];

    struct direction V;  //normal flow  velocity in four directions in local cell
    struct direction V_neighbor;   //normal flow velocity in four directions coming from neighbor cell

};

//Fluxes calculated for the local cell and the neighbor cells
 struct Fluxes{
    //Normal Flux vector elements (F*nx  +G*ny) at each cell face locally
    struct vector_element F_s;
    struct vector_element F_e;
    struct vector_element F_n;
    struct vector_element F_w;
    //Normal Flux vector elements (F*nx +G*ny) at each cell face from neighbor cells
    struct vector_element F_s_neighbor;
    struct vector_element F_e_neighbor;
    struct vector_element F_w_neighbor;
    struct vector_element F_n_neighbor;

    struct vector_element URs;
    struct vector_element URe;
    struct vector_element URn;
    struct vector_element URw;
};



///functions
void read_geometry(struct grid_point *gp);
void calc_geometry(struct grid_point *gp, struct cell_center *cell);
void initial_conditions(struct cell_center *cell ,float M1,float gamma);

void calc_flow_properties(struct cell_center *cell,float gamma);


#endif // HEADER_H_INCLUDED 
You have probably run out of stack memory.

Also, for example, a cell_centre object contains just ONE value of each of the fluid-dynamical properties, not a large array of them?
Last edited on
yes, I think it's a large array( multiple arrays), but it was working without any problem in the original single main.cpp file. Once I moved the declaration of the structs to the header.h, I start getting the error.

why didn't I run out of stack memory in the first situation, but I did in the second one?
is it a wrong way to use structs with a header file?
is it a wrong way to use structs with a header file?

No, it is not wrong. It's pretty much required if you need these struct types in multiple source files.

There's no way this "was working without any problem in the original single main.cpp". It makes absolutely no difference whatsoever. Try putting it all back in main.cpp and it will have the same problem.

You should rethink your problem to determine if you really need all of that complexity, but if you really do need it all you can make it work by simply putting the keyword "static" in front of all the variable definitions that use these structs in main.
Topic archived. No new replies allowed.