From owner-freebsd-chat@FreeBSD.ORG Thu Apr 22 14:43:12 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 D588E16A4CE for ; Thu, 22 Apr 2004 14:43:12 -0700 (PDT) Received: from castle.comp.uvic.ca (castle.comp.uvic.ca [142.104.5.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id B14FA43D3F for ; Thu, 22 Apr 2004 14:43:12 -0700 (PDT) (envelope-from chrisa@uvic.ca) Received: from uvic.ca (S01060050bab00fcb.gv.shawcable.net [24.68.226.164]) i3MLhB5w4989020; Thu, 22 Apr 2004 14:43:11 -0700 Message-ID: <40883C6F.5090602@uvic.ca> Date: Thu, 22 Apr 2004 14:43:11 -0700 From: Chris Ashlee User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: DoubleF 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> In-Reply-To: <20040422030636.GA444@Shark.localdomain> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-UVic-Virus-Scanned: OK - Passed virus scan by Sophos (sophie) on castle X-UVic-Spam-Scan: castle.comp.uvic.ca Not_scanned_LOCAL X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) 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: Thu, 22 Apr 2004 21:43:12 -0000 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 */ > } > Based on my (limited) knowledge of C++, the constructor for the object 'a' of type A will be called before main... So if you were to translate this to C, the other module, which doesn't know about the A module, would have to have a call to the constructor inserted before any other code in main, and 'a' would have to be referenced from the module containing main. So it seems that some information would be lost in the translation to C, namely that some details of other modules should not be visible. However, the compiled code for both the C++ program and the C translation could well wind up the same. Any high-level optimizations that can be done on C++ but not C could probably be done in the translation itself. Remember, C is basically a glorified, portable assembly language, and just about anything can be translated to it - even machine code. It's translating to a more high-level language that's hard. Chris