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?


inline int abs1(int x) {
    return x<0 ? -x : x;
}
#define abs2(x) ((x)<0 ? -(x) : x)
 
int r = abs1(-7);
int s = abs2(-7);

>An inline function is NOT a macro, it's still a function.  You can't use a 
>function as an initializer for a static extent variable in C.

OK, this is not valid in ANSI C
In C++, however, this is valid.
Now, take a look at the assembly output (x86,regparm)

.data
s:	.long 7
.bss
r:	.zero	4
.text
__static_initialization_and_destruction_0:
	cmpl $65535,%edx
	jne .L86
	testl %eax,%eax
	je .L86
	movl $7,r
.L86:	ret
_GLOBAL_.I.s:
	movl $65535,%edx
	movl $1,%eax
	call __static_initialization_and_destruction_0
	ret
.section	.ctors,"aw"
	.long	 _GLOBAL_.I.s

Why is 'r' not handled as 's'?
This is slower and occupies more memory.


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