Article View: comp.std.c++
Article #2329Re: pre/post conditions, and pointer-testing (was Re: F90 vs C++/C, optimization question?)
From: Eric Biederman
Date: Fri, 27 Oct 1995 18:22
Date: Fri, 27 Oct 1995 18:22
50 lines
2592 bytes
2592 bytes
In article <martelli.814695566@cadlab> martelli@cadlab.cadlab.it (Alex Martelli ) writes: ... >Hmmm. Suppose you claim that X[20][20] and Y[20] are not aliases of >each other. What's wrong with: >assert(&Y[20] <= &X[0][0] && X[20][20] >= Y[0]); >(apart from the obvious fact that it's not portable)? Well, another obvious fact is that you probably meant '||', not '&&':-). Seriously, the problem with this is that it's not just "not portable", it's *UNDEFINED BEHAVIOUR* to compare pointers that are not pointing inside the same array -- a perfectly compliant compiler could make demons fly out of your nose as a consequence of this code. Couldn't we do something like // select the correct allocator for the memory model typedef Allocator::diff_t diff_t // I think that's what it calls ptrdif_t diff_t value1 = &Y[20] - &X[0][0] diff_t value2 = &X[20][20] - &Y[0] assert(value1 <= 0 || value2 >= 0); If my memory holds the difference type for the allocator functions is defined to hold the difference between any two pointers in the memory model. Or is this an oversite in the draft, to seem to allow this? I could look at the wording some more, and in other places but what is the intent here? [snip] [ lots of neat portable ideas, that can be implemented if, the above is true. ] [snip] [class preconditions/postconditions ] assert's and runtime test aren't great but they can do this, is a semiportable way. The real question is can we express what we want to assert? Eric --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<EBIEDERM.95Oct27110922@cse.unl.edu>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<45tq00$dkd@hawk.hcsc.com> <465q4m$j07@wcap.centerline.com> <46is0j$j7c@hawk.hcsc.com> <46kuem$j45@manuel.anu.edu.au> <martelli.814695566@cadlab>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 27 Oct 95 18:22:55 GMT Approved: fjh@cs.mu.oz.au From: ebiederm@cse.unl.edu (Eric Biederman) Newsgroups: comp.std.c++ Subject: Re: pre/post conditions, and pointer-testing (was Re: F90 vs C++/C, optimization question?) X-Original-Date: 27 Oct 1995 16:09:22 GMT Organization: University of Nebraska--Lincoln Message-ID: <EBIEDERM.95Oct27110922@cse.unl.edu> References: <45tq00$dkd@hawk.hcsc.com> <465q4m$j07@wcap.centerline.com> <46is0j$j7c@hawk.hcsc.com> <46kuem$j45@manuel.anu.edu.au> <martelli.814695566@cadlab> In-Reply-To: martelli@cadlab.cadlab.it's message of 26 Oct 1995 17:46:32 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMJEji+EDnX0m9pzZAQEp2QGAn0pl8TKCFhvqr51GOjvSltBdobRTU6e+ tzeImQnZwa+8frvENCbPoFCVb3i16ksS =gpAi