linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is it helpful for a compiler to optimize?
@ 2012-06-03  6:38 Krzysztof
  2012-06-03  6:59 ` Krzysztof
  2012-06-03  8:03 ` Jesse Ruffin
  0 siblings, 2 replies; 4+ messages in thread
From: Krzysztof @ 2012-06-03  6:38 UTC (permalink / raw)
  To: linux-c-programming

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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-04 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-03  6:38 Is it helpful for a compiler to optimize? Krzysztof
2012-06-03  6:59 ` Krzysztof
2012-06-04 14:09   ` Srinivasa T N
2012-06-03  8:03 ` Jesse Ruffin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).