Path: utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!helios!diamond!jdm5548 From: jdm5548@diamond.tamu.edu (James Darrell McCauley) Newsgroups: comp.lang.c Subject: FAQ - malloc array - clarify Keywords: malloc, Sun, lint Message-ID: <8056@helios.TAMU.EDU> Date: 7 Sep 90 16:57:29 GMT Sender: usenet@helios.TAMU.EDU Reply-To: jdm5548@diamond.tamu.edu (James Darrell McCauley) Organization: Texas A&M University Agricultural Engineering Dept Lines: 41 Could someone lend a hand? Topic is FAQ #19, allocating memory for an array. The problem is that 'lint' doesn't like what I'm doing. Here's some source: #include #include main() { int i, nrows=10, ncolumns=10; double **array; array = (double **)malloc(nrows * ncolumns * sizeof(double *)); for(i = 0; i < nrows; i++) array[i] = (double *)malloc(ncolumns * sizeof(double)); } /* Code from answer to #19 in FAQ list (dated Aug 3 by 'ls -l'): int **array = (int **)malloc(nrows * ncolumns * sizeof(int *)); for(i = 0; i < nrows; i++) array[i] = (int *)malloc(ncolumns * sizeof(int)); */ /* output from lint: test.c(8): warning: possible pointer alignment problem test.c(10): warning: possible pointer alignment problem malloc, arg. 1 used inconsistently llib-lc(383) :: test.c(8) malloc, arg. 1 used inconsistently llib-lc(383) :: test.c(10) */ Why am I getting these warnings? I get them using lint that (I assume) is bundled with the OS. SunOS Release 4.0.3c on a Sparc. If I run them on my Sun 3/60 with SunOS Release 4.0.3, I don't get the warnings. ('diff "4.0.3" "4.0.3c"' ?) Do I have a broken lint on the Sparc? Should the argument to malloc be cast (unsigned) (and FAQ list changed)? If I make this change, lint doesn't scream about arguments being used incorrectly. Darrell McCauley