In C, what exactly are the performance benefits that come with observing strict aliasing?
In C, what exactly are the performance benefits that come with observing strict aliasing?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a page that describes aliasing very thoroughly here.
There are also some SO topics here and here.
To summarize, the compiler cannot assume the value of data when two pointers of different types are accessing the same location (i.e. it must read the value every time and therefore cannot make optimizations).
This only occurs when strict aliasing is not being enforced. Strict aliasing options:
Example
Copy-paste this code into main.c:
Then compile the code with these options:
And you will get:
Disable aliasing with:
And the warning goes away. (Or just take out -Wall but…don’t compile without it)
Try as I might I could not get MSVC to give me a warning.