Mail Archives: djgpp/1996/11/11/14:59:18
Toby Ounsted wrote:
> > > : > KeyWords = (char **) malloc ( sizeof(char) );
> Okay...I *MUST* be a genius then, because I already knew that...let me
> clarify..I've seen, used and even explained type casting in numerous
> situations, I've also seen, used and even explaine dthe purpose and
> methods behind allocating memory for arrays of..well...anything I need
> arrays of...what I don't recognize is that double asterisk..*THAT* I've
> never seen...which is what I was referring to..so, what did I miss, if
> anything, and when? DJGPP doesn't lend much to online syntax referral,
> in any way(that I know).
This is ANSI C; nothing DJGPP-specific. You should get a book on ANSI C.
To allocate an array of N ints using malloc, one uses the following syntax:
int *array = (int *) malloc(N*sizeof(int));
Note how one needs a pointer to an int to store the dynamically-allocated
array. malloc's void * return value must be cast to the appropriate type
to appease the ANSI C gods.
Now if, on the other hand, one wants an array of N _pointers to ints_, then
one uses the same rule to come up with the syntax:
int **array = (int **) malloc(N*sizeof(int *));
Since what you want is an array of pointers, you need a pointer to a
pointer to point to it.
--
Erik Max Francis | max AT alcyone DOT com
Alcyone Systems | http://www.alcyone.com/max/
San Jose, California | 37 20 07 N 121 53 38 W
&tSftDotIotE | R^4: the 4th R is respect
"But since when can wounded eyes see | If we weren't who we were"
- Raw text -