Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 186589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:40:24+00:00 2026-05-11T15:40:24+00:00

In C, what exactly are the performance benefits that come with observing strict aliasing?

  • 0

In C, what exactly are the performance benefits that come with observing strict aliasing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:40:25+00:00Added an answer on May 11, 2026 at 3:40 pm

    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:

    • gcc: -fstrict-aliasing [default] and -fno-strict-aliasing
    • msvc: Strict aliasing is off by default. (If somebody knows how to turn it on, please say so.)

    Example

    Copy-paste this code into main.c:

    void f(unsigned u) {     unsigned short* const bad = (unsigned short*)&u; }   int main(void) {     f(5);      return 0; } 

    Then compile the code with these options:

    gcc main.c -Wall -O2

    And you will get:

    main.c:3: warning: dereferencing type-punned pointer will break strict-aliasing rules

    Disable aliasing with:

    gcc main.c -fno-strict-aliasing -Wall -O2

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What exactly does null do performance and storage (space) wise in MySQL? For example:
Exactly that: Does a strings length equal the byte size? Does it matter on
Note: I know exactly what a property is. This question is about performance. Using
I'm having some performance issues calling CGContextDrawLayerAtPoint in iOS 4 that didn't seem to
What exactly are performance counters and how do they work? Are they specific to
What exactly are mock tests...I need to know the mock and performance tests available
So why exactly is it that it's always recommended to use const as often
After going through few articles about performance, Not able to get this statement exactly.
I've been asked to measure the performance of a fortran program that solves differential
How can I test performance of an asp.net mvc application and understand where exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.