Re: Optimizing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Magnus Fromreide <magfr@xxxxxxxxxxxxxx> writes:

> Is it a valid optimization for the compiler to generate the same
> instructions for f2 as it generates for f1?

It isn't.

(1) foo could modify the data:

int foo(int writable, const void *p, int size)
{
        if (writable) {
                memset((void *) p, 0, size);
	}
        return 0;
}

Although the second parameter is const void *, the language still
allows the function to modify the object to which that points,
provided that the object was not defined as const.  This is okay
with f2 but not with f1.

(2) In f2, buf must have a different address at each level of recursion:

int foo(int flag, const void *p, int size)
{
        static const void *outer = NULL;
        if (outer == NULL) {
		outer = p;
        	f2();
                outer = NULL;
	} else {
		assert(p != outer);
	}
        return 0;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux