cpshelley@violet.waterloo.edu (cameron shelley) (10/09/90)
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
jimp@cognos.UUCP (Jim Patterson) (10/09/90)
In article <1990Oct9.032131.16992@watdragon.waterloo.edu> cpshelley@violet.waterloo.edu (cameron shelley) writes: >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. That's funny. It works for me. I'm using gcc 1.21, Sun 3/60, Sun OS 4.03. What are you running on? (It might just be relevant). Note: this is a REALLY OLD version of GCC. -- Jim Patterson Cognos Incorporated UUCP:uunet!mitel!cunews!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 3755 Riverside Drive NOT a Jays fan (not even a fan) Ottawa, Ont K1G 3Z4
cpshelley@violet.uwaterloo.ca (cameron shelley) (10/10/90)
In article <8909@cognos.UUCP> jimp@cognos.UUCP (Jim Patterson) writes: >In article <1990Oct9.032131.16992@watdragon.waterloo.edu> cpshelley@violet.waterloo.edu (cameron shelley) writes: >>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. > >That's funny. It works for me. I'm using gcc 1.21, Sun 3/60, Sun OS 4.03. >What are you running on? (It might just be relevant). > >Note: this is a REALLY OLD version of GCC. Well, I'm running on a Microvax II actually, I'm not sure of the gcc release though. Anyway, following a suggestion, I deleted the #include <stdlib.h> line and declared calloc myself in the file: char *calloc(int a, unsigned int b); which then proceeded to work fine. Btw, calloc was declared in exactly this manner in <stdlib.h> (extern of course), so I'm still not quite sure what's going on here. But its obviously with the way gcc is set up on this machine, not with gcc in general. -- 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