Mail Archives: djgpp/2000/06/28/14:15:31
radsmail AT juno DOT com (Radical NetSurfer) wrote in
<5t7klskbj285civf9serk693otnho6t5j0 AT 4ax DOT com>:
>Can some one please tell me if these two statements
>are corrent _and_ do the same thing?
>
>THANSK!
>
>BITMAP *Pieces[3234];
>PALLETE PPpal[3234];
this is getting very off topic. questions regarding the C language should
be addressed to comp.lang.c and comp.lang.c.moderated rather than the
DJGPP newsgroup.
you can answer your question by asking whether
double* dp[3234];
int i[3234];
do the same thing.
incidentally, the comp.lang.c faq has a good section on pointers/memory
allocation.
>how would the above statements, be converted into malloc-type
>statements, such that the user would be able to specify ONLY as many
>Bitmaps/Palettes are required...
>
> Pieces = (BITMAP**)malloc(3234 * sizeof(BITMAP*));
don't cast the return value of malloc if you are using C. this will
prevent to from noticing if you forgot to include stdlib.h.
once you allocate space for an array of pointers, you need to also make
sure each element of the array actually points to valid storage.
you can use something along the lines of:
/* untested code */
#include <stdlib.h>
int** arralloc_int(int*** p, size_t obj_count) {
size_t i;
*p = malloc(obj_count*sizeof(int));
if( *p == NULL )
return *p;
for(i=0; i < obj_count; i++) {
printf("%lu\n", i);
*(*p + i) = malloc(sizeof(int));
}
return *p;
}
void arrfree_int(int*** p, size_t obj_count) {
size_t i;
if( *p != NULL ) {
for(i=0; i<obj_count; i++) {
printf("%lu\n", i);
if( *(*p + i) != NULL ) {
free(*(*p + i));
*(*p + i) = NULL;
}
}
free(*p);
*p = NULL;
}
return;
}
--
--------------------------------
A. Sinan Unur
http://www.unur.com/
- Raw text -