From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13543 invoked by alias); 18 Dec 2001 00:20:29 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 13396 invoked from network); 18 Dec 2001 00:20:27 -0000 Received: from unknown (HELO smtp2.ihug.co.nz) (203.109.252.8) by sources.redhat.com with SMTP; 18 Dec 2001 00:20:27 -0000 Received: from ihug.co.nz (p37-apx1.akl.ihug.co.nz [203.173.192.37]) by smtp2.ihug.co.nz (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id NAA11860 for ; Tue, 18 Dec 2001 13:20:25 +1300 X-Authentication-Warning: smtp2.ihug.co.nz: Host p37-apx1.akl.ihug.co.nz [203.173.192.37] claimed to be ihug.co.nz Message-ID: <3C1E8C80.9C69D482@ihug.co.nz> Date: Mon, 17 Dec 2001 16:43:00 -0000 From: Ross Smith Organization: No thanks X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.0-4GB i686) X-Accept-Language: en MIME-Version: 1.0 To: gcc@gcc.gnu.org Subject: Re: Big-endian Gcc on Intel IA32 References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2001-12/txt/msg00960.txt.bz2 Linus Torvalds wrote: > > I actually think that it might be equally powerful to just have a way of > "tainting" certain pointers, and disallowing their use at compile-time > unless the recipient claims to accept the specific form of "tainting". > This is, in fact, more-or-less what the "const" qualifier does, but it > might be useful to allow user-defined "taints". You can do this already in C++. (Of course I realise this isn't much help for a large C application like the kernel.) // Andrei Alexandrescu's static assertion template // (this is in everybody's library by now) template struct static_assert; template <> struct static_assert {}; // This is valid only if there are no bits in Src that aren't in Dst template struct convert_check: static_assert<((Src | Dst) == Dst)> {}; // Template for qualified types // Each bit in Mask represents a type qualifier template class qualified { public: qualified(T t = T()): value_(t) {} operator T() const { static_assert<(Mask == 0)>(); return value_; }; template qualified(qualified src): value_(src.value_) { convert_check(); } template friend qualified qualified_cast(qualified src) { return qualified(src.value_); } private: T value_; }; // Define a couple of type qualifiers const unsigned magic(1); const unsigned tainted(2); // Examples of use int main() { int i(42); // Plain int qualified m; // Magic int qualified mt; // Magic, tainted int mt = i; // OK, can add qualifiers // m = mt; // This won't compile m = qualified_cast(mt); // But this will return 0; } -- Ross Smith ...................................... Auckland, New Zealand r-smith@ihug.co.nz ......................... http://storm.net.nz/~ross/ "We need a new cosmology. New gods. New sacraments. Another drink." -- Patti Smith