Re: Allocation of a multidimensional array of structures
- From: Michel Rouzic <Michel0528@xxxxxxxx>
- Date: Sat, 23 Jun 2007 19:29:34 -0700
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.
.
- Follow-Ups:
- Re: Allocation of a multidimensional array of structures
- From: Barry Schwarz
- Re: Allocation of a multidimensional array of structures
- References:
- Allocation of a multidimensional array of structures
- From: Michel Rouzic
- Re: Allocation of a multidimensional array of structures
- From: CBFalconer
- Allocation of a multidimensional array of structures
- Prev by Date: Re: Linux-like GCC compiler for WIndows?
- Next by Date: Re: Allocation of a multidimensional array of structures
- Previous by thread: Re: Allocation of a multidimensional array of structures
- Next by thread: Re: Allocation of a multidimensional array of structures
- Index(es):
Relevant Pages
|