Re: Optimization attributes const vs. pure

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

 



On 28/05/12 14:35, Johannes Bauer wrote:
> So "pure" would be the perfect fit: Global memory is read but not
> modified (which is also asserted by passing the arguments as "const").
> Why is gcc then not doing the optimization that I'd want it to perform?
I have no idea.
I wondered if it feared fprintf changing global variables on which
intcmp() depended,
so I modified it to create the following program, where there is no
side-effect.
But it still exhibits the same behavior (intcmp called 100 times if
pure, 1 if const).

#include <stdio.h>
#include <string.h>
#include "int.h"
int main() {
    struct mi a, b;
    int vals[100];
    memset(&a, 0, sizeof(struct mi));
    memset(&b, 0, sizeof(struct mi));
    for (unsigned int i = 0; i < 100; i++) {
        vals[i] = intcmp(&a, &b);
    }
    for (unsigned int i = 0; i < 100; i++) {
        fprintf(stderr, "%d\n", vals[i]);
    }
    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