Re: Allocation of a multidimensional array of structures




CBFalconer wrote:
Michel Rouzic wrote:

I've recently met issues with my program which can only be
explained by heap corruption, so I've tried debugging my program
with Valgrind, and here's what I get with the following
multidimensional array allocation code :

typedef struct
{
int32_t speed;
int16_t height;
} lut_entry;

lut_entry ***lut; // <-global pointer

void lut_alloc()
{

Apart from the other comments, why are you using K&R C rather than
properly prototyped C functions?

In case you're refering to writing void lut_alloc(); and then void
lut_alloc(){...} I have yet to find out how it is better to do things
this way. But since there was a why in your question I guess it's
because it's simpler, it avoids a redundancy that I deem useless
(maybe out of ignorance?) and it avoid making mistakes by changing a
line and not changing the other one accordingly.

Or to turn the question around, why should I use that prototyping
thing?

After fixing that, consider
passing parameters rather than using globals.

Well, while I'm aware that it's better to avoid using globals, it's
really more convenient to make the LUT global here, considered it's
more convenient to write code this way and that it'd make one more
argument to pass from function to function, so I don't see why I
shouldn't use a global pointer here.

.



Relevant Pages

  • [FW] Prices in Dollars (2011)
    ... Substantial penalty for early withdrawal. ... Avoid contact with skin. ... Limited time offer, call now to ensure prompt delivery. ... This article is void where prohibited, taxed, or otherwise ...
    (rec.games.miniatures.warhammer)
  • Re: Malcolms new book
    ... From a compiler writer's point of view, of course, it is important that if) is legal whilst if) is not. ... Similalry from an algorithms point of view we are not too interested in whether a function receives its parameters as arguements or in globals. ... returning void. ... A lot of C functions also have a primary purpose of ...
    (comp.lang.c)
  • Re: Allocation of a multidimensional array of structures
    ... so I've tried debugging my program ... Or to turn the question around, why should I use that prototyping ... just good practice and helps avoid undefined behavior. ... Well, while I'm aware that it's better to avoid using globals, it's ...
    (comp.lang.c)
  • Re: Global variables crashing my app
    ... We're experiencing 'memory access' crashes when somehow the globals are ... This DLL is a pure ... Somehow mpBuff is being ... void DestroyParams; ...
    (microsoft.public.vc.language)
  • Re: critique my program!
    ... void printar; ... int array; ... array is what is called a global variable. ... globals are not the way. ...
    (comp.lang.c)