Thread View: comp.std.c++
1 messages
1 total messages
Started by Shankar Unni
Sat, 02 Dec 1995 10:05
Question about another C++ optimization
Author: 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads