This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Volatile constants?
- To: <gcc at gcc dot gnu dot org>
- Subject: Re: Volatile constants?
- From: "Christian Häggström" <97nv46 at skola dot kiruna dot se>
- Date: Mon, 03 Apr 2000 11:32:06 +0200
- Cc: <rearnsha at arm dot com>, <J dot A dot K dot Mouw at its dot tudelft dot nl>
> 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?