Comments: Authenticated sender is From: "George Foot" To: puva AT earthlink DOT net Date: Sat, 22 Aug 1998 20:19:51 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Local Variables Reply-to: george DOT foot AT merton DOT oxford DOT ac DOT uk CC: djgpp AT delorie DOT com Message-Id: Precedence: bulk On 22 Aug 98 at 14:38, puva AT earthlink DOT net wrote: > I don't know if i'm sending this question to the right place or not, > hehe, but I can't seem > to use local variables in my source files. Like: > > void main() > { > int a; > } > > would give an error like, "parse error before int" or "parse error > before a". It works fine if the variables are outside of main(), but not > anything local. Is there something wrong with how the compiler is setup? > or is there a header missing or something? Did you actually try to compile the above code? It works for me. Note though that `main' should return `int'. I think perhaps you're trying to declare local variables other than at the start of a block. This is not allowed (in C), and is a horrible thing to want to do anyway. If you want a local variable to have limited scope in a function, make a subblock: #include int main (void) { char s = 'X'; printf ("Outside subblocks: s = %c\n", s); { char *s = "Hello world!"; /* Start of block, so we can declare */ printf ("In first subblock: s = %s\n", s); } printf ("Outside subblocks again: s = %c\n", s); { int s = 5; /* Start of another block -- this is a */ /* different `s' */ printf ("In second subblock: s = %d\n", s); } printf ("Outside subblocks yet again: s = %c\n", s); return 0; } Output: Outside subblocks: s = X In first subblock: s = Hello world! Outside subblocks again: s = X In second subblock: s = 5 Outside subblocks yet again: s = X -- george DOT foot AT merton DOT oxford DOT ac DOT uk