This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Volatile constants?


> Because even in C++ you have still specified it as a constructor function, 
> not a constant expression.

Is there any way to optimize away constant constructors?
Otherwise, an new option to manage this have been nice.
---
I have another example of GCC's silly constant handling
assume we have an array like this
    int regs[8];
and we want to access 'regs[3]' as 'ebx'

( best viewed with fixed size font )

method 1 const pointer   | method 2 const reference
----------------------   | ------------------------
                // definitions //
typedef int * intp;      | typedef int & intref;
const intp ebx = regs+3; | const intref ebx = regs[3];
              // access example //
void set_ebx(int val) {  | void set_ebx(int val) {
    *ebx = val;          |     ebx = val;
}                        | }
        // asm output (i386,regparm) //
set_ebx:                 | set_ebx:
    movl %eax,regs+12    |     movl %eax,%edx
                         |     movl ebx,%eax
                         |     movl %edx,(%eax)
    ret                  |     ret
                         | .section .rodata
                         | ebx:
                         | .long regs+12

I want to use method 2 because it is cleaner, but do I get different output?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]