It's known that big local/global variables may cause to a stack overflow. I know that using pointers and allocating space in memory helps to overcome this problem. But is it the only option? What happens if I have (or need) too-many pointers in global scope?
Regarding the stack space: Is a global struct-type variable takes space in the stack, or acts like a pointer? Do I need to create a pointer of a struct variable type in order to reduce the stack load?
Does the following code allocates memory also to the char** variable named
BIG
?// in the header file typedef struct myStruct { BIG[256][256]; int baz; } myStruct; // in the c file myStruct* foo; foo = (myStruct*) malloc( sizeof(*foo) );
How can I easily cast the return value of
malloc()
? In question #3 I wrote:foo = (myStruct*) malloc( sizeof(*foo) );
But I prefer to write something like:
foo = (foo) malloc( sizeof(*foo) ); // the compiler reports an error
Which will ease the pain when editing the code (when changing the type of
foo
).
English isn't my native language so sorry for any lack of clarity.