Globally declared arrays



Hi guys,

I just tried to give advice to a colleague who has a problem program in
C, and I was interested to hear the thoughts of this forum on the
subject.

I've been an occasional programmer in C for about a year now, so by no
means an expert, so it would be good to know if I'm leading my
colleague down the wrong path.

The error he's having is fairly obscure and relates to our own function
calls communicating with our own hardware, so I won't go into details.
Basically, does this sound like a reasonable thing to say:

I noticed that my colleague was declaring local arrays on the stack,
and also that he had a number of global variables and even a global
array on the stack. The arrays on the stack total less than 64k
(win32). The global array is only a few k. I said that in my mind, it
was just plain bad practice to have a globally declared array and to
have arrays declared on the stack. I told him to redo the whole thing
with pointers, malloc() and free and then see if the problems vanish.

Does this seem a reasonable thing to advise or am I, as I suspect my
colleague believes, just being pedantic and splitting hairs?

Cheers,

Robin

.



Relevant Pages

  • Re: ALLOCATABLE arrays
    ... || If try to create a very large array on the stack and you do not have enough ... || Allocating on the heap gives you access to a hell of a lot more memory (well ... and "heap" (and there probably are/were some computers which don't/didn't ... | Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)
  • Re: Fortran memory allocation (stack/heap) issues
    ... > rather than Fortran, ... dynamic allocation, and relatively little stack allocation. ... value return and arrays by reference. ...
    (comp.lang.fortran)
  • Re: Need some help understanding array definitions
    ... Data structures defined with VARIABLE, CREATE, VALUE, CONSTANT, and related words are, indeed, all global. ... Unlike some languages, Forth doesn't discourage defining global data structures, but it's important to understand their proper use. ... They provide for "persistent" data, as well as space for strings and arrays. ... Strings and arrays should be in defined data structures and referenced by address and length or address on the stack. ...
    (comp.lang.forth)
  • Re: heap allocation of arrays
    ... | to force all arrays to be allocated on the heap. ... | the stack would be replaced with pointers on the stack. ... | heap is easier to detect than failure to allocate space on the ...
    (comp.lang.fortran)
  • Re: dynamic allocation vs array
    ... > It seems that we would expect some performance hit if we were to use dynamic ... > recommendation to minimize this performance hit or totally avoiding it ... You are using arrays with non-constant size ... stack access. ...
    (comp.lang.cpp)