Mail Archives: djgpp/2002/12/14/08:30:05.2
Lars O. Hansen wrote:
> Still stripped down, but this always crashes when compiled with gcc -pedantic -Wall is.c -lalleg
When I comment out the allegro calls, add the #inclusion of <stdio.h> to
provide the declaration for the variadic function printf (required bt the
standard), and change the #inclusion of "stdlib.h", you code compiles and
runs for me with no problems:
#include <stdio.h> /* mha - added. */
#include <stdlib.h> /* mha - "stdlib.h". Are you sure you
* don't have a "stdlib.h" masking
* <stdlib.h>? */
#define arraysize 360
#define stype int
#define rtype float
#define trigtype float
#define id 1024
#define PHI 1.0
#define statusx 10
#define statusy 440
stype array_size = arraysize - 1;
rtype *cm;
trigtype *cxphi;
trigtype *sxphi;
rtype *a;
trigtype *b;
rtype *le;
trigtype *an;
stype *ak, *ek;
trigtype phi = PHI;
int somecolor0, somecolor1, somecolor2, textforegroundcolor,
BACKGROUND_COLOR;
char status_string[] = " ";
void setupall(void);
void init_arrays(void);
void freeall(void);
void cls(void);
int main()
{
setupall();
freeall();
exit(0);
}
void cls(void)
{
#if 0 /* mha */
show_mouse(NULL);
clear_to_color(0, BACKGROUND_COLOR);
status_string[sprintf(status_string + 19, "%.1f", phi) + 19] = 32;
textout(0, 0, status_string, statusx, statusy, textforegroundcolor);
#endif
}
void init_arrays(void)
{
int i = array_size - 1;
cm = malloc(3 * sizeof(rtype) * array_size); /* ! we allocate #of *
* needed times memory
*/
cxphi = malloc(4 * sizeof(trigtype) * array_size);
ak = malloc(2 * sizeof(stype) * array_size);
a = cm + sizeof(rtype) * array_size; /* then we adjust the pointers
* ! */
le = a + sizeof(rtype) * array_size;
sxphi = cxphi + sizeof(trigtype) * array_size; /* Please adjust the *
* #times and add */
b = sxphi + sizeof(trigtype) * array_size; /* assignments here *
* appropriately ! */
an = b + sizeof(trigtype) * array_size;
ek = ak + sizeof(stype) * array_size;
if (cm == NULL || cxphi == NULL || ak == NULL) { /* so we also have
* to check less!
* adjust ! */
printf("nomemstring");
exit(0);
}
do {
cm[sizeof(rtype) * i] = id;
}
while (i--);
cls();
}
void freeall(void)
{
if (cm == 0 || cxphi == 0 || ak == 0) { /* so we also have to check *
* less! adjust ! */
printf("0?");
#if 0 /* mha */
while (!kbhit()) ;
#endif
exit(0);
}
free(cm);
free(cxphi);
free(ak);
}
void setupall(void)
{
atexit(freeall);
init_arrays();
}
- Raw text -