Volatile constants?
Christian Häggström
97nv46@skola.kiruna.se
Mon Apr 3 02:33:00 GMT 2000
> 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?
More information about the Gcc
mailing list