Mail Archives: djgpp/2000/06/28/16:15:24.1
From: | Radical NetSurfer <radsmail AT juno DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Are THESE two statements EQUAL?
|
Date: | Wed, 28 Jun 2000 16:10:08 -0400
|
Message-ID: | <7qmkls0k46jupmhklc5sqesf999hn7vmjl@4ax.com>
|
References: | <5t7klskbj285civf9serk693otnho6t5j0 AT 4ax DOT com>
|
X-Newsreader: | Forte Agent 1.8/32.548
|
X-No-Archive: | yes
|
MIME-Version: | 1.0
|
NNTP-Posting-Host: | 216.202.134.205
|
X-Original-NNTP-Posting-Host: | 216.202.134.205
|
X-Trace: | 28 Jun 2000 16:12:37 -0400, 216.202.134.205
|
Lines: | 89
|
X-Original-NNTP-Posting-Host: | 64.31.79.51
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
They most certainly ARE on topic, as I'm having SegFaults
specific to DJ _and_ allegro, BITMAP* is an Allegro object,
as it Pallete.... thus the relevancy.
I'll consider your information below.
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 -