Newsgroups: gnu.gcc.help,comp.parallel.mpi From: "Mark S. Novojilov" Subject: Re: Mixing data declarations with function calls Organization: Universitaet Trier Date: Fri, 19 Sep 1997 03:45:01 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <3421D91D.99CB2319@explorer.uni-trier.de> Paul Bristow wrote: > The following, trivial piece of MPI/C code compiles fine so long as I omit > the line "int k;", however, if I leave it in I get the following: > > new.c: In function `main': > new.c:21: parse error before `int' > *** Error code 1 > make: Fatal error: Command failed for target `new' > > Unfortunately, I have a need to mix function calls and data declarations. > MPI is using gcc as its C compiler. My guess is that it is gcc enforcing > good programing style rather than a problem with MPI. Does anybody know? > And more importantly if it is a 'feature' any ideas how I turn it off? gcc is not inforcing good style, but inforcing correct C syntax.In C you can't declare variables at any place you like, only at the beginning of {...} block! From the code below I don't see why you need to declare k between fuction calls. Maybe I didn't understand something. Declare k at the beginning of main, or make a {} block around the scope of k, or use C++. > Thanks, > Paul C Bristow. > > #include > #include > #define LIST_NO_BLOCKS 2 > > typedef struct LNode *ListPtr; > > typedef struct LNode{ > int Data; > ListPtr Next; > }ListNode; > typedef int DummyPtr; > > void main(int argc,char *argv[]){ > int NoProcs,MyId; > MPI_Aint Extent; > > int ArrayOfBlockLengths[LIST_NO_BLOCKS]={1,1}; > MPI_Type_extent(MPI_INT,&Extent); > > int k; > MPI_Init(&argc,&argv); > MPI_Comm_size(MPI_COMM_WORLD,&NoProcs); > MPI_Comm_rank(MPI_COMM_WORLD,&MyId); > > > MPI_Finalize(); > > }