calloc problem in gnu???

cameron shelley cpshelley at violet.waterloo.edu
Tue Oct 9 13:21:31 AEST 1990


Hello!

  I've run into a bit of a problem!  The following code is a very
simplified version of what I've been trying to do (allocate space
for an array in a separate function).  Using gcc, the program 
compiles but when run only produces "Illegal Instruction" on stderr.

  However, when I remove the "void"s from int *init(void), and compile
with cc, it works fine!  This is driving me crazy!  Is there something
about gnu or perhaps ansi c that I don't understand?

				Cam

************************** code here ***********************

#include <stdio.h>
#include <stdlib.h>
int *init(void);

main() {

  int *ip, i=0;

  ip = init();
  if (ip != (int *)0)
    for (i = 0; i < 10; i++)
      printf("%d\n",*(ip+i));
  else 
    printf("calloc failed\n");
}

int *init(void) {

  return (int *) calloc(10,sizeof(int));

}
--
      Cameron Shelley        | "Saw, n.  A trite popular saying, or proverb. 
cpshelley at violet.waterloo.edu|  So called because it makes its way into a
    Davis Centre Rm 2136     |  wooden head."
 Phone (519) 885-1211 x3390  |				Ambrose Bierce



More information about the Comp.lang.c mailing list