From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 923 invoked by alias); 27 Oct 2009 23:06:47 -0000 Received: (qmail 915 invoked by uid 22791); 27 Oct 2009 23:06:47 -0000 X-SWARE-Spam-Status: No, hits=-10.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_PASS X-Spam-Check-By: sourceware.org Received: from proofpoint2.lanl.gov (HELO proofpoint2.lanl.gov) (204.121.3.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Oct 2009 23:06:41 +0000 Received: from mailrelay2.lanl.gov (mailrelay2.lanl.gov [128.165.4.103]) by proofpoint2.lanl.gov (8.14.3/8.14.3) with ESMTP id n9RN6d2G005140 for ; Tue, 27 Oct 2009 17:06:39 -0600 Received: from alvie-mail.lanl.gov (alvie-mail.lanl.gov [128.165.4.110]) by mailrelay2.lanl.gov (Postfix) with ESMTP id C8FC815CB46E for ; Tue, 27 Oct 2009 17:06:39 -0600 (MDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by alvie-mail.lanl.gov (Postfix) with ESMTP id C6AF67D00AD for ; Tue, 27 Oct 2009 17:06:39 -0600 (MDT) X-NIE-2-Virus-Scanner: amavisd-new at alvie-mail.lanl.gov Received: from [130.55.124.157] (manticore.lanl.gov [130.55.124.157]) by alvie-mail.lanl.gov (Postfix) with ESMTP id B66867D00A9 for ; Tue, 27 Oct 2009 17:06:39 -0600 (MDT) Subject: Re: containers tentative design summary From: Gerard Jungman To: gsl-discuss@sourceware.org In-Reply-To: References: <1254708349.18519.4.camel@ForbiddenPlanet> <7f1eaee30910050750l738876b1p41e6bd8ae5aa6d16@mail.gmail.com> <1254783367.28192.98.camel@manticore.lanl.gov> Content-Type: multipart/mixed; boundary="=-ImNmJz1qvqiDF3mb5hzz" Date: Tue, 27 Oct 2009 23:06:00 -0000 Message-Id: <1256684949.19313.2.camel@manticore.lanl.gov> Mime-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=1.12.8161:2.4.5,1.2.40,4.0.166 definitions=2009-10-27_13:2009-09-29,2009-10-27,2009-10-27 signatures=0 Mailing-List: contact gsl-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gsl-discuss-owner@sourceware.org X-SW-Source: 2009-q4/txt/msg00027.txt.bz2 --=-ImNmJz1qvqiDF3mb5hzz Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 722 On Fri, 2009-10-23 at 14:58 +0100, Brian Gough wrote: > > I think this is an interesting example. How would these two classes > work in practice in C? For example, how would one pass a non-const > matrix (taken as a view of a non-const multi-array) to a function > taking a const matrix argument. Dealing with the interaction between > const and non-const arguments is a fundamental issue. > The challenge for any scheme is getting reasonable const behavior in > C. If that problem can be solved better then everything else follows > more easily. Ok. The attachment is the obvious solution. I don't want to have theological wars about this, but it seems to me like it is the "C way". Let's debate. -- G. Jungman --=-ImNmJz1qvqiDF3mb5hzz Content-Disposition: attachment; filename="foobar.c" Content-Type: text/x-csrc; name="foobar.c"; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 1438 #include /* The union guarantees that the structs are aligned, in C99. * * In C90, standard does not discuss the issue, but all * compilers known to man align them anyway. The C99 * guarantee seems to be an attempt to standardize * that behaviour. * * The union type is never actually used, unless somebody * can think of a reason to use it... */ union gsl_vector_union_t { struct gsl_vector_struct_t { double * data; size_t size; int stride; } as_vector; struct gsl_const_vector_struct_t { const double * data; size_t size; int stride; } as_const_vector; }; typedef struct gsl_vector_struct_t gsl_vector; typedef struct gsl_const_vector_struct_t gsl_const_vector; void gsl_some_typical_function(const gsl_vector * v) { /* do something which might twiddle v.data[] */ } void gsl_some_typical_const_function(const gsl_const_vector * v) { /* do something which does not twiddle v.data[] */ } int main() { gsl_vector v; gsl_const_vector cv; /* might be twiddling v.data[] */ gsl_some_typical_function(&v); /* claims not to twiddle cv.data[] */ gsl_some_typical_const_function(&cv); /* claims not to twiddle v.data[] */ gsl_some_typical_const_function((const gsl_const_vector *) &v); /* a misuse; but this sort of thing can never be prevented anyway */ gsl_some_typical_function((const gsl_vector *) &cv); return 0; } --=-ImNmJz1qvqiDF3mb5hzz--