Is it helpful for a compiler to optimize?

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

 



Let's have a below code:

struct st
{
    int iv;
    /*...*/
};

void afun(struct st *stp)
{
    stp->iv++;
    printf("%d\n",stp->iv);
}

Is it helpful for a compiler to do better optimization if I write the function as this?

void afun(struct st *stp)
{
    int liv=stp->iv++;

    printf("%d\n",liv);
}

In other words, is it better from optimization point of view to do assignments structure members values to local variables then do what you need to and then assign them back to member variables?

--
Regards
Krzysztof J.


--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux