Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!titcca!anprda!qmfl!spee From: spee@qmfl.jrdc.go.jp (Paul SPEE) Newsgroups: comp.lang.c Subject: Re: Array bounds checking with C???? Message-ID: <869@qmfl.jrdc.go.jp> Date: 27 Aug 90 04:18:59 GMT References: <7611@ucdavis.ucdavis.edu> Reply-To: spee@paul.jrdc.go.jp (Paul SPEE) Organization: Research Development Corporation of Japan, Tokyo, Japan Lines: 47 In article <7611@ucdavis.ucdavis.edu> kuan@iris.ucdavis.edu (Frank [Who me?] Kuan) writes: > Why is it that most C compilers don't seem to support this > nifty little feature? To be able to check the array boundaries, the C compiler must now the array size. However, in most important cases the C compiler does not have this information. This can be either be the case when an array is passed as a function parameter or is allocated as a dynamic array. It would have been convenient if ANSI would have allowed 'pointers to variable size arrays'. For example, int array[10]; int * f(n, a) int n; int (*a)[n]; { register i; int (*b)[n] = (void *) malloc(n * sizeof(int)); for (i = 0; i < n; i++) (*b)[i] = (*a)[i]; return (int *) b; } main() { f(sizeof(array), array); } (Note: gcc allows this.) The same problem is true not only for runtime checking but also for parallizing scientific code. See %A Randy Allen %A Steve Johnson %T Compiling C for Vectorization, Parallelization, and Inline Expandsion %J Proceedings of the SIGPLAN '88 Conference on Programming Language Design and Implementation %D June 22-24, 1988 %C Atlanta, Georgia %P 241-249 %L ALLEN88 Paul Spee