From owner-freebsd-chat@FreeBSD.ORG Thu Apr 22 19:41:06 2004 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 151AD16A4CE for ; Thu, 22 Apr 2004 19:41:06 -0700 (PDT) Received: from mx.tele-kom.ru (mx.tele-kom.ru [213.80.148.6]) by mx1.FreeBSD.org (Postfix) with SMTP id 8435A43D41 for ; Thu, 22 Apr 2004 19:41:02 -0700 (PDT) (envelope-from doublef@tele-kom.ru) Received: (qmail 69412 invoked by uid 555); 23 Apr 2004 06:41:00 +0400 Received: from shark (213.80.149.134) by t-k.ru with TeleMail/2 id 1082688059-69393 for freebsd-chat@freebsd.org; Fri, 23 Apr 06:40:59 2004 +0400 (MSD) Received: by shark (Postfix, from userid 1000) id 6BBE121E; Fri, 23 Apr 2004 06:40:55 +0400 (MSD) Date: Fri, 23 Apr 2004 06:40:54 +0400 From: Sergey Zaharchenko To: Chris Ashlee Message-ID: <20040423024054.GA350@Shark.localdomain> Mail-Followup-To: Sergey Zaharchenko , Chris Ashlee , DoubleF , freebsd-chat@freebsd.org References: <200404202124.50967.dgw@liwest.at> <20040421110548.20d8e75c.cpressey@catseye.mine.nu> <6.0.1.1.1.20040421191223.03ed1a88@imap.sfu.ca> <20040421124817.5811bddb.cpressey@catseye.mine.nu> <20040422030636.GA444@Shark.localdomain> <40883C6F.5090602@uvic.ca> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="C7zPtVaVf+AK4Oqc" Content-Disposition: inline In-Reply-To: <40883C6F.5090602@uvic.ca> User-Agent: Mutt/1.4.2.1i cc: DoubleF cc: freebsd-chat@freebsd.org Subject: Re: Beginning C++ in FreeBSD X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2004 02:41:06 -0000 --C7zPtVaVf+AK4Oqc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 22, 2004 at 02:43:11PM -0700, Chris Ashlee probably wrote: > DoubleF wrote: > >[etc] If you think C++ can be translated to C, just translate this: > > > >// one module > > > >class A > >{ > >public: > > A(); > >}; > > > >A::A() > >{ > > /* some code here */ > >} > > > >static A a; > > > >// another module, which doesn't know about the former's existance > > > >int > >main(void) > >{ > > /* some other code here */ > >} > > >=20 > Based on my (limited) knowledge of C++, the constructor for the object=20 > 'a' of type A will be called before main... Yes, that's the catch... > So if you were to translate=20 > this to C, the other module, which doesn't know about the A module,=20 > would have to have a call to the constructor inserted before any other=20 > code in main, and 'a' would have to be referenced from the module=20 > containing main. >=20 > So it seems that some information would be lost in the translation to C,= =20 > namely that some details of other modules should not be visible.=20 > However, the compiled code for both the C++ program and the C=20 > translation could well wind up the same. You would have to translate a program as a whole, not on a file-per-ile basis, then. I agree that in the end you will get something compilable --- but it will have large dependency chains which aren't really necessary, and you'd have to recompile the main module each time the A module's interface changes, which is certainly inefficient...=20 > Any high-level optimizations=20 > that can be done on C++ but not C could probably be done in the=20 > translation itself. Remember, C is basically a glorified, portable=20 > assembly language, and just about anything can be translated to it -=20 > even machine code. It's translating to a more high-level language that's= =20 > hard. What you surely can't translate is the A module without the main module. Suppose I want a shlib to initialize itself when it's loaded. I create a static object and GCC does the rest of the stuff for me (like creating an init function visible to the linker). But what would you do in C (of course, you want it portable, so no init hacks, please...). --=20 DoubleF Fourth Law of Revision: It is usually impractical to worry beforehand about interferences -- if you have none, someone will make one for you. --C7zPtVaVf+AK4Oqc Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFAiII1wo7hT/9lVdwRApC9AJ4gNgUwH9pIFhJOizQY6vZZgpHBhwCfUAkB deWeN5cAG9fGlq2nUSBJEII= =0Ull -----END PGP SIGNATURE----- --C7zPtVaVf+AK4Oqc--