Article View: comp.std.c++
Article #2816Question about another C++ optimization
From: Shankar Unni
Date: Sat, 02 Dec 1995 10:05
Date: Sat, 02 Dec 1995 10:05
37 lines
1656 bytes
1656 bytes
Consider the code: void foo(const int &); int x; ... foo(x); Can an optimizer assume that x is not going to be modified, and keep it in a register across the call? Or can it convert the parameter (if foo is inlined) into a value parameter (for ints, this is usually a win)? We've been trying to read the language in the draft WP (possibly a little too deeply). It seems to imply that if you cast a const pointer or reference to a non-const type and dereference it to assign to it, it is legal if the original object it is pointing to was non-const.. This would basically make the "const" information absolutely useless to the caller, and act only as a sort of rap on the knuckles if you actually try to assign it *directly*.. Is this really the intent of the standard? That a compiler cannot assume in the above code that x is not modified? -- Shankar Unni E-Mail: shankar@sgi.com Silicon Graphics Inc. Phone: +1-415-933-2072 URL: http://reality.sgi.com/employees/shankar --- [ 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:
<49nvh5$ac6@fido.asd.sgi.com>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: shankar@engr.sgi.com (Shankar Unni) Newsgroups: comp.std.c++ Subject: Question about another C++ optimization Date: 02 Dec 1995 10:05:52 GMT Organization: Silicon Graphics, Inc., Mountain View, CA Approved: Matt@Austern Message-ID: <49nvh5$ac6@fido.asd.sgi.com> Reply-To: shankar@engr.sgi.com NNTP-Posting-Host: austern.hip.berkeley.edu