Consider below C program.
If we call as “func()”it will return constant 1. But it is also possible to call the function as “func((double *)&a)” which was supposed to return 1 but returning something else. The code was made to return constant 1 only! That’s a big problem but STRICT ALIASING fixes it.
Use restrict qualifier keyword. It means you promise the compiler that something is not aliased with the pointer restrict keyword. If you break your promise you will only suffer. Please refer restrict keyword in C for details.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Strict Aliasing Rule in C with Examples
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- Why C treats array parameters as pointers?
- Why is the size of an empty class not zero in C++?
- Why copy constructor argument should be const in C++?
- Why "&" is not used for strings in scanf() function?
- Why is a[i] == i[a] in C/C++ arrays?
- Why is C considered faster than other languages ?
- Why variable name does not start with numbers in C ?
- Why only subtraction of addresses allowed and not division/addition/multiplication
- Why does sizeof(x++) not increment x in C?
- Why strcpy and strncpy are not safe to use?
- Why are elementwise additions much faster in separate loops than in a combined loop?
- Why array index starts from zero ?
- Why learning C Programming is a must?
- Why to use fgets() over scanf() in C?
- Why do we need reference variables if we have pointers
- Else without IF and L-Value Required Error in C
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.