🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.x
Article #236

Re: parse error when compile?

#236
From: StefanHundhammer
Date: Tue, 29 Sep 1998 00:00
68 lines
2897 bytes
In article <36102de8.0@ruby.hknet.com>,
  Filippino@fair.game.com wrote:
>
> When I was trying to compile the following code, I always got the
> parsing error at line 32 before * .
[snip]
 >       if(!XRecordQueryVersion(dpy1, rcmajor, rcminor)) {
>          exit(0);
>       }
>       if((*rcmajor < 1) && (*rcminor < 13)){
>          fprintf(stderr, "Please install the record extension greater than
1.13");
>       }
>
>       XRecordRange *rcRange[];                          /* <=== parse error
here before * . */
>       rcRange[0] = XRecordAllocRange();
>
>       int nclients = 0;
>       int nrange = 0;
>       int rcDataFlag = 0;
>
>       rdcontext = XRecordCreateContext(dpy1, rcDataFlag, XRecordAllClients,
nclients, rcRange, nrange);
>       if(rdct == 0){
>          fprintf(stderr, "Cannot create RecordContext");
>          exit(1);
>       }
>
>    }

ANSI C permits you to declare variables at the *beginning* of each new block -
but certainly not everywhere within the block. What you did here was mix code
and declarations. The correct sequence is:

{
   /* declarations */
   XRecordRange *rcRange[];
   rcRange[0] = XRecordAllocRange();
   ...

   /* executable code */
   rdcontext = XRecordCreateContext(...);
   ...
}

Thus, either (a) move your declarations to the function beginning or
(b) open a new block with curly braces ( "{" / "}" ) and declare your
new variables at the beginning of this new block.

Be advised, though, that (b) is frequently considered poor programming style -
although this is a matter of personal taste.


--
Stefan Hundhammer     (Stefan.NOSPAM.Hundhammer@datech.heitec.de)
                      (remove NOSPAM. to send mail -
                       sorry for this inconvenience)

HEITEC Datentechnik GmbH * Schuhstr. 30 * 91009 Erlangen * Germany
Tel.: +49-9131/877-218 * Fax: +49-9131/877-222

http://www.datech.heitec.de



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Technical Details
Message-ID: <6uqluo$2po$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36102de8.0@ruby.hknet.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,8fe7b01c96b459ae
X-Google-Attributes: gid11318c,public
X-Google-Thread: f4bda,8fe7b01c96b459ae
X-Google-Attributes: gidf4bda,public
X-Google-Thread: 11038b,8fe7b01c96b459ae
X-Google-Attributes: gid11038b,public
From: StefanHundhammer@my-dejanews.com
Subject: Re: parse error when compile?
Date: 1998/09/29
Message-ID: <6uqluo$2po$1@nnrp1.dejanews.com>
X-Deja-AN: 395945794
References: <36102de8.0@ruby.hknet.com>
X-Http-Proxy: 1.0 x3.dejanews.com:80 (Squid/1.1.22) for client 195.63.13.14
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Tue Sep 29 13:05:28 1998 GMT
Newsgroups: comp.os.linux.x,comp.windows.x.intrinsics,gnu.gcc.help
X-Http-User-Agent: Mozilla/4.04 [en] (WinNT; I)