delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/30/03:28:33

From: "Marp" <marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: problems with extern
Date: Fri, 30 Jun 2000 02:04:58 -0400
Organization: MindSpring Enterprises
Lines: 29
Message-ID: <8jhdcf$art$1@slb6.atl.mindspring.net>
References: <n1colsooqlrmkltk8f3b2hgnbinmj67jvk AT 4ax DOT com>
NNTP-Posting-Host: 04.30.99.99
X-Server-Date: 30 Jun 2000 06:06:07 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Sean Proctor" <sproctor AT ccs DOT neu DOT edu> wrote in message
news:n1colsooqlrmkltk8f3b2hgnbinmj67jvk AT 4ax DOT com...
> alright, either there's a bug in djgpp or I'm an idiot... I have 4
> files. okay, here's how it's set up, pretty much
> file1.c:
> ...
> #include "file1.h"
> #include "file2.h"
> ...
> int function(Blah a)
> {
> init_location(locations);
> FILE *fp = fopen("file", "rt); /* this is the offending line
> according to the compiler... but the error goes away if I comment out
> the line above, no I didn't forget the semi-colon. ;) */

You can only declare local variables at the beginning of the scope of the
code. Since you have a function call before the FILE *fp declaration, it
gives you an error. C++ does not have this limitation, but C does. You also
mismatched the quote marks in the code you posted. You should do this
instead:

FILE *fp;
init_location(locations);
fp = fopen("file", "rt");

<snip>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019