Newsgroups: comp.lang.c
Path: utzoo!utgpu!watserv1!maytag!watdragon!violet.waterloo.edu!cpshelley
From: cpshelley@violet.waterloo.edu (cameron shelley)
Subject: calloc problem in gnu???
Message-ID: <1990Oct9.032131.16992@watdragon.waterloo.edu>
Sender: daemon@watdragon.waterloo.edu (Owner of Many System Processes)
Organization: University of Waterloo
Distribution: na
Date: Tue, 9 Oct 90 03:21:31 GMT
Lines: 41

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@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
