strict-aliasing Questions

4

The program - some sort of old-school network messaging: // Common header for all network messages. struct __attribute__((packed)) MsgHeader { uint32_t msgType; }; // One of network messages. str...
Kinser asked 5/6, 2015 at 12:45

4

While read another question about aliasing ( What is the strict aliasing rule? ) and its top answer, I realised I still wasn't entirely satisfied even though I think I understood it all there. (Th...
Veneaux asked 15/7, 2015 at 11:31

1

Code 1: unsigned int *p = malloc(sizeof *p); memset(p, 0x55, sizeof *p); unsigned int u = *p; Code 2: void *d = malloc(50); *(double *)d = 1.23; memset(d, 0x55, 50); unsigned int u = *(unsign...
Hairless asked 21/6, 2015 at 23:14

4

Solved

Rust has strict aliasing rules. But can I work around them if "I know what I'm doing"? I'm trying to convert to Rust a C function that performs a complicated operation by reading from input buffer...
Cretonne asked 22/5, 2015 at 22:37

5

Solved

Using gcc 4.9.2 20150304 64 bit I bumped into this apparently strange behavior: double doit() { double *ptr = (double *)malloc(sizeof(double)); ptr[0] = 3.14; return (double)((uintptr_t) ptr); ...
Gadid asked 9/5, 2015 at 8:1

1

One of the major uses of restrict keyword that was added to C99 is to allow compilers to load something into a register and assume that the register will mirror the state of the variable thus loade...

2

Solved

The question relates to this post. Some authoritative users stated that the following code breaks strict aliasing rules. #include <boost/static_assert.hpp> template <typename T> stru...
Teetotal asked 25/3, 2015 at 10:28

5

Solved

My company uses a messaging server which gets a message into a const char* and then casts it to the message type. I've become concerned about this after asking this question. I'm not aware of any ...
Kinson asked 18/3, 2015 at 11:45

2

Solved

3.10/10 says: If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: However, the term "access" is n...
Ligule asked 12/3, 2015 at 3:20

1

Clarification: My question is: Is it UB to use an lvalue of type int to access an object of effective type const int ? This question has two code samples which use an lvalue of type int t...
Vistula asked 18/2, 2015 at 1:42

3

Solved

I have integer values that are used to access data in unrelated data stores, i.e., handles. I have chosen to wrap the integers in a struct in order to have strongly typed objects so that the differ...
Hightoned asked 15/2, 2015 at 18:20

4

Solved

I've compiled this in gcc and g++ with pedantic and I don't get a warning in either one: #include <stdio.h> #include <stdlib.h> #include <string.h> struct a { struct a *next; ...
Parlin asked 14/2, 2015 at 22:52

3

Solved

I'm trying to understand the implications of the following statement in the C99 standard (C99; ISO/IEC 9899:1999 6.5/7) An object shall have its stored value accessed only by an lvalue expressi...
Transcription asked 10/2, 2015 at 14:40

2

Solved

The more I read, the more confused I get. The last question from the related ones is closest to my question, but I got confused with all words about object lifetime and especially - is it OK to on...
Adumbral asked 30/1, 2015 at 15:59

3

Solved

I'm reading paragraph 7 of 6.5 in ISO/IEC 9899:TC2. It condones lvalue access to an object through: an aggregate or union type that includes one of the aforementioned types among its members ...
Lindsy asked 12/1, 2015 at 18:41

1

If according to strict aliasing rule char pointer may point to any type pointer, then why can't I cast any-type pointer to char pointer using static_cast? char *ptr; int *intPtr; ptr = reinterpre...
Heisel asked 22/10, 2014 at 7:16

3

Solved

I recently came across a strange deoptimization (or rather missed optimization opportunity). Consider this function for efficient unpacking of arrays of 3-bit integers to 8-bit integers. It unpack...

3

I recently asked this question: Using this pointer causes strange deoptimization in hot loop The problem was that I was writing to an array of type uint8_t and the compiler treated it as if it co...
Szabadka asked 10/10, 2014 at 10:42

1

Solved

My understanding is that the following code has undefined behaviour in C++ due to something called "strict aliasing rule". #include <cstdint> enum Foo : int16_t {}; void test(Foo& foo)...
Bookish asked 2/10, 2014 at 14:38

3

My program conforms to the strict aliasing rule, except for one place: a compilation unit which contains hashing functions such as MurmurHash3, SpookyHash, etc. On x86 and x86_64, these hashing fun...
Neural asked 10/9, 2014 at 11:45

2

Solved

In these comments user @Deduplicator insists that the strict aliasing rule permits access through an incompatible type if either of the aliased or the aliasing pointer is a pointer-to-character typ...
Downthrow asked 6/7, 2014 at 17:16

1

Solved

I am trying to use two libraries, LIBSVM and LIBLINEAR in the same application that I am writing in C++11. Both LIBSVM and LIBLINEAR take their input in what is essentially a row-based sparse matri...
Derward asked 5/8, 2014 at 10:22

1

Solved

Question about type punning: why does this code break strict aliasing rules: int main() { int a = 1; short j; printf("%i\n", j = *((short*)&a)); return 0; } and this is not: int main()...
Pomology asked 4/8, 2014 at 11:39

1

Solved

I've been reading up on the strict aliasing rules over the last week or so and ran into this article: Understanding C/C++ Strict Aliasing. The article goes through several ways two swap the halves...
Lovely asked 21/7, 2014 at 16:1

1

Solved

(Note: Although this question is about "store", the "load" case has the same issues and is perfectly symmetric.) The SSE intrinsics provide an _mm_storeu_pd function with the following signature: ...
Sjambok asked 16/7, 2014 at 17:39

© 2022 - 2024 — McMap. All rights reserved.