The C standard says that the effective type is passed. Therefore, by definition, all relevant compilers pass an efficient type.
The sample code causes undefined behavior, violating the strict alias rule, because the value of the effective long type is read by the value l of the long long type.
This is also true in C89, I'm not sure what you are talking about "new rules in C99" (except that long long not in C89).
It is true that when C is standardized, some existing code had undefined behavior. And it’s also true that people continue to write code with undefined behavior.
What is meant by "copied as an array of character type"?
This means that you need to copy incremental characters using a character type.
What would be the correct way to copy data in an agnostic style?
It’s impossible to “erase the effective type”, as far as I know. To correctly read the value using long long * , you must point to the location of the effective type long long long long * .
In your code, for example:
// If we have confirmed that long and long long have the same size and representation long long x; memcpy(&x, p, sizeof x); return x;
Another option is channel merging.
If you don't like all this then compile with -fno-strict-aliasing .
source share