Re: Why is get_current() not const function?

Manfred Spraul (manfred@colorfullife.com)
Mon, 17 Mar 2003 20:11:06 +0100


This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-1940-1047928330-0001-2
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Is it possible to use __attribute__((const) with inline functions?
I tried that, but it seems that gcc ignores __attribute__((const) and
looks at the contents of the function instead.

I've tried the attached test app: With gcc-3.2.1 (gcc -O3), and
"inlconst" was called 10 times, constfnc only once.

--
    Manfred

--=_courier-1940-1047928330-0001-2 Content-Type: text/plain; name="consttest.c"; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="consttest.c"

#include <stdio.h> #include <stdlib.h>

static int constfnc(int x) __attribute__((const));

static inline int inlconst(int x) __attribute__((const));

static void dummy(int i);

static inline int inlconst(int x) { printf("in inlconst.\n"); return 2; }

int main(void) { int i; for(i=0;i<10;i++) { dummy(constfnc(0)); } for (i=0;i<10;i++) { dummy(inlconst(0)); } }

int constfnc(int x) { printf("in const.\n"); return 1; }

void dummy(int i) { }

--=_courier-1940-1047928330-0001-2--