Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNightCreature83

Posted 23 April 2013 - 03:37 PM

What level are you compiling this at because if any optimisations are on the compiler will just ignore the declaration of "x" as it can tell you are never going to use it. And even then the CPU can shift all of these instructions around if it likes so there is no way to say for certain it won't just initialise x at the beginning of the function or even at all.

All you will get when initialising the parameter is a initialised but unused variable detected warning which is what I expected anyway, and that is in a debug build with no optimisations on btw.

A compiler is allowed to change your code as long as the instruction that make it into the executable have the same behaviour as what you expressed in the code. So it is very likely you are just running into a compiler transformation that makes the code more efficient to execute. If you are interested in knowing more about these kind of transformations you should watch this as it explains what the compiler and CPU are allowed to do in the face of multithreading and it's barriers(semaphore, mutex, critical section): http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-1-of-2

#3NightCreature83

Posted 23 April 2013 - 03:37 PM

What level are you compiling this at because if any optimisations are on the compiler will just ignore the declaration of "x" as it can tell you are never going to use it. And even then the CPU can shift all of these instructions around if it likes so there is no way to say for certain it won't just initialise x at the beginning of the function or even at all.

All you will get when initialising the parameter is a initialised but unused variable detected warning which is what I expected anyway, and that is in a debug build with no optimisations on btw.

A compiler is allowed to change your code as long as the instruction that make it into the executable have the same behaviour as what you expressed in the code. So it is very likely you are just running into a compiler transformation that makes the code more efficient to execute. If you are interested in knowing more about these kind of transformations you should watch this as it explains what the compiler and CPU are allowed to do in the face of multithreading and it's barrier: http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-1-of-2

#2NightCreature83

Posted 23 April 2013 - 03:35 PM

What level are you compiling this at because if any optimisations are on the compiler will just ignore the declaration of "x" as it can tell you are never going to use it. And even then the CPU can shift all of these instructions around if it likes so there is no way to say for certain it won't just initialise x at the beginning of the function or even at all.

All you will get when initialising the parameter is a initialised but unused variable detected warning which is what I expected anyway, and that is in a debug build with no optimisations on btw.

A compiler is allowed to change your code as long as the instruction that make it into the executable have the same behaviour as what you expressed in the code. So it is very likely you are just running into a compiler transformation that makes the code more efficient to execute.

#1NightCreature83

Posted 23 April 2013 - 03:33 PM

What level are you compiling this at because if any optimisations are on the compiler will just ignore the declaration of "x" as it can tell you are never going to use it. And even then the CPU can shift all of these instructions around if it likes so there is no way to say for certain it won't just initialise x at the beginning of the function or even at all.

All you will get when initialising the parameter is a initialised but unused variable detected warning which is what I expected anyway, and that is in a debug build with no optimisations on btw.

PARTNERS