Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!almaak.usc.edu!ajayshah From: ajayshah@almaak.usc.edu (Ajay Shah) Newsgroups: comp.lang.c Subject: Novice C question Message-ID: <31969@usc> Date: 15 Apr 91 22:28:22 GMT Sender: news@usc Organization: University of Southern California, Los Angeles, CA Lines: 30 Nntp-Posting-Host: almaak.usc.edu Originator: ajayshah@almaak.usc.edu Consider this fragment of C code (from Numerical Recipes): 1 double *dvector(nl,nh) 2 int nl,nh; 3 { 4 double *v; 5 6 v=(double *)malloc((unsigned) (nh-nl+1)*sizeof(double)); 7 if (!v) nrerror("allocation failure in dvector()"); 8 return v-nl; 9 } It's supposed to be a function which allocates a vector of doubles. My interpretation of nl and nh is: they're array indexes. If you want to allocate an array going from 5 to 10, you would say p = dvector(5, 10). Question: what is happening on line 8? Why is he not just returning v (a pointer)? What is the meaning of subtracting nl (an int) from v without any casting? Thanks! -ans. -- _______________________________________________________________________________ Ajay Shah, (213)734-3930, ajayshah@usc.edu The more things change, the more they stay insane. _______________________________________________________________________________