From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16690 invoked by alias); 17 Dec 2002 17:08:52 -0000 Mailing-List: contact gsl-discuss-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gsl-discuss-owner@sources.redhat.com Received: (qmail 16681 invoked from network); 17 Dec 2002 17:08:49 -0000 Received: from unknown (HELO chinook.phys.nwu.edu) (129.105.206.190) by 209.249.29.67 with SMTP; 17 Dec 2002 17:08:49 -0000 Received: (from ato@localhost) by chinook.phys.nwu.edu (8.11.6/8.11.6) id gBHH4b608550 for gsl-discuss@sources.redhat.com; Tue, 17 Dec 2002 11:04:37 -0600 Date: Tue, 17 Dec 2002 15:22:00 -0000 From: Atakan Gurkan To: gsl-discuss@sources.redhat.com Subject: Re: Forward declaration is not possible Message-ID: <20021217110437.A8524@chinook.phys.nwu.edu> References: <200212121428.04612.p.haase@tu-harburg.de> <15866.482.683337.337101@debian> <200212171713.19437.p.haase@tu-harburg.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <200212171713.19437.p.haase@tu-harburg.de>; from p.haase@tu-harburg.de on Tue, Dec 17, 2002 at 05:13:19PM +0100 X-SW-Source: 2002-q4/txt/msg00259.txt.bz2 On Tue, Dec 17, 2002 at 05:13:19PM +0100, Peter Haase wrote: > Hi Brian, > I'm writing a library* that provides some functions that are useful for > developing simulation programs. For that reason I programmed a class called > RandomGenerator: > > //in myrandom.h: > #include > > class RandomGenerator > { [deleted] > }; [deleted] > > //in myrandom.h: > // !This isn't needed anymore: #include ! > > //Forward declaration: > struct gsl_rng; > > class RandomGenerator > { [deleted] > }; > > Unfortunatley this forward declaration is not possible if gsl_rng is declared > as follows: > > typedef struct { > char* name; > /*... */ > } gsl_rng; > > but the forward declaration is possible if gsl_rng is declared as follows: > > typedef struct gsl_rng { > char* name; > /*... */ > } gsl_rng; > > Note, that code that is already existing can be used with that declaration as > it was before! I'm not shure if it is strict ANSI C to use gsl_rng as a name > for the struct and as the name of the new type introduced by the typedef > statement. But at least in C++ it is standard conform (see C++ ARM s. 106): > 'A typedef may be used to redefine a name to refer to the type to which it > already refers - even in the scope where the type was originally declared. > For example: > typedef struct s { /* */ } s;' > > *(actually I'm not writing a library, but I think that is a more common case. > So look to it as an abstract example) > > Hope this makes it a bit more clearer, what I would like to do. > > Thanks, > Peter Hi, First, my apologies in advance if I am wrong. I did not actually try the idea that I am about to suggest. Why can you not do something like: typedef struct gsl_rng gsl_rng_typedefed; and then use gsl_rng_typedefed for your C++ class? I do not mean to object to your proposed change, I have no idea what the consequences of that would be, I am just trying to suggest a way for you to get things going. cheers, ato