strict-aliasing Questions
2
Solved
Consider the following code on a platform where the ABI does not insert padding into unions:
union { int xi; } x;
x.xi = 1;
I believe that the second line exhibits undefined behaviour as it viol...
Dogmatist asked 5/8, 2016 at 8:7
3
Solved
I've tried to read up on the other questions here on SO with similar titles, but they are all a tiny bit too complex for me to be able to apply the solution (or even explanation) to my own issue, w...
Refund asked 25/7, 2016 at 13:53
1
Assuming I have a union like this
union buffer {
struct { T* data; int count; int capacity; };
struct { void* data; int count; int capacity; } __type_erased;
};
Will I get into trouble if I mi...
Tideway asked 19/7, 2016 at 7:36
2
Solved
Questions:
Does this code below violate strict aliasing rules? That is, would a smart compiler be allowed to print 00000 (or some other nasty effect), because a buffer first accessed as other typ...
Joyance asked 13/7, 2016 at 9:41
2
Solved
Does the following program violate the strict aliasing rule?
#include <cstdint>
int main()
{
double d = 0.1;
//std::int64_t n = *reinterpret_cast<std::int64_t*>(&d); // aliasin...
Aestivation asked 23/6, 2016 at 17:23
2
See
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html
(http://pubs.opengroup.org/onlinepubs/9699919799 is from Issue 7 - from 2013 and still the same!)
sockaddr_stor...
Maceio asked 6/6, 2016 at 15:17
1
I'm confused by the strict aliasing rules when it comes to casting a char array to other types. I know that it is permitted to cast any object to a char array, but I'm not sure what happens the oth...
Nummary asked 18/5, 2016 at 14:32
2
Solved
Just a couple weeks ago, I learned that the C++ Standard had a strict aliasing rule. Basically, I had asked a question about shifting bits -- rather than shifting each byte one at a time, to maximi...
Moxa asked 16/5, 2016 at 17:38
1
Solved
I recently was surprised to learn that the C and C++ language standards have a "strict aliasing" rule. In essence, the rule prohibits variables of differing types from referencing the same memory l...
Ury asked 12/5, 2016 at 2:52
3
Solved
I recently learned that the C++ standard contains "strict aliasing rules", which forbid referencing the same memory location via variables of different types.
However, the standard does allows for...
Tjaden asked 12/5, 2016 at 4:51
7
Solved
I used the following piece of code to read data from files as part of a larger program.
double data_read(FILE *stream,int code) {
char data[8];
switch(code) {
case 0x08:
return (unsigned char)...
Skin asked 14/7, 2010 at 12:48
3
Suppose we have a pointer T* ptr; and ptr, ptr+1, … ptr+(n-1) all refer to valid objects of type T.
Is it possible to access them as if they were an STL array? Or does the following code:
std::ar...
Mealie asked 8/4, 2016 at 20:42
1
I am trying to determine whether the following code invokes undefined behavior:
#include <iostream>
class A;
void f(A& f)
{
char* x = reinterpret_cast<char*>(&f);
for (int i...
Arad asked 6/4, 2016 at 17:9
3
Solved
One of the first results for strict aliasing on google is this article
http://dbp-consulting.com/tutorials/StrictAliasing.html
One interesting thing I noticed is this: http://goo.gl/lPtIa5
uint32_...
Traitor asked 30/12, 2015 at 10:34
2
Solved
The Question
The question of whether all pointers derived from pointers to structure types are the same, is not easy to answer. I find it to be a significant question for the following two primary...
Guerra asked 19/6, 2014 at 10:32
13
Consider the following code (p is of type unsigned char* and bitmap->width is of some integer type, exactly which is unknown and depends on which version of some external library we're using):
...
Concuss asked 24/11, 2015 at 16:3
2
Suppose we get some data as a sequence of bytes, and want to reinterpret that sequence as a structure (having some guarantees that the data is indeed in the correct format). For example:
#include ...
Shivaree asked 11/12, 2015 at 12:20
2
Solved
Me and a colleague are trying to achieve a simple polymorphic class hierarchy. We're working on an embedded system and are restricted to only using a C compiler. We have a basic design idea that co...
Labia asked 17/7, 2015 at 13:44
1
Solved
I have looked at the following — related — questions, and none of them seem to address my exact issue: one, two, three.
I am writing a collection of which the elements (key-value pairs) are stored...
Becht asked 23/10, 2015 at 22:25
5
Solved
I have a Result<T> template class that holds a union of some error_type and T. I would like to expose the common part (the error) in a base class without resorting to virtual functions.
Here...
Greg asked 11/10, 2015 at 19:18
3
According to both C99 §6.2.5p27 and C11 §6.2.5p28:
All pointers to structure types shall have the same representation and
alignment requirements to each other.
With a footnote (#39 and #48 re...
Bobettebobina asked 6/6, 2014 at 12:0
1
Solved
I'm proposing a change to a library whose public API currently looks like this:
typedef size_t enh; /* handle */
int en_open(enh *handle)
{
struct internal *e = malloc(...);
*handle = (enh)e;
...
Skean asked 28/8, 2015 at 21:2
2
Solved
I've got a question about strict-aliasing rules, unions and standard. Assume we have the following code:
#include <stdio.h>
union
{
int f1;
short f2;
} u = {0x1};
int * a = &u.f1;
sh...
Fellowman asked 12/8, 2015 at 14:48
4
I am facing confusion about the C++ strict-aliasing rule and its possible implications. Consider the following code:
int main() {
int32_t a = 5;
float* f = (float*)(&a);
*f = 1.0f;
int32_...
Brisk asked 6/9, 2013 at 13:48
3
I've been trying to understand a particular aspect of strict aliasing recently, and I think I have made the smallest possible interesting piece of code. (Interesting for me, that is!)
Update: Base...
Valenza asked 21/7, 2015 at 9:4
© 2022 - 2024 — McMap. All rights reserved.