undefined-behavior

What might cause “Undefined Behaviour” in this parallel GPU code?

依然范特西╮ 提交于 2019-12-25 16:57:41
问题 Lets assume core1 and core2 try writing their variables a and b to same memory location. How can UB be explained here? We dont know if a or b is written to that memory location(as a last action). We dont even know what is written there (a garbage) Even the target memory address can be miscalculated(segfault?). Some logical gates make wrong currents and CPU disables itself CPU's frequency information becomes corrupt and goes high overclock(and break itself) Can I assume only the first option

Explanation of the UB while changing data

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 04:08:27
问题 I was trying to demonstrate to a work pal that you can change the value of a constant-qualified variable if really wants to (and knows how to) by using some trickery, during my demostration, I've discovered that exists two "flavours" of constant values: the ones that you cannot change whatever you do, and the ones that you can change by using dirty tricks. A constant value is unchangeable when the compiler uses the literal value instead of the value stored on the stack (readed here), here is

Dangling References leading to undefined behavior

五迷三道 提交于 2019-12-25 04:04:49
问题 I had asked a previous question about references and undefined behavior here: previous question and based on the answer given and some of the comments such as the comment by user2079303 where they stated this: A reference wrapper works fine, if you have one "master" container that contains the objects themselves (not references) that is never modified, and other containers have references to the master My new question becomes this: Will this help alleviate the possibility of dangling

Why can't non-POD objects be copied with memcpy? [duplicate]

牧云@^-^@ 提交于 2019-12-25 03:32:39
问题 This question already has answers here : Why isn't memcpy guaranteed to be safe for non-POD types? (5 answers) Closed 4 years ago . According to various sources I've read, the following C++ code invokes undefined behaviour: class A { public: virtual void method () { std::cout << "Hello" << std::endl; } }; ... A *a, *b; // obtain 2 Instances from somewhere, then... memcpy (a, b, sizeof(A)); a->method(); Why does this cause undefined behaviour? I can see no logical implementation of the

What is a valid pointer in gcc linux x86-64 C++?

余生长醉 提交于 2019-12-24 19:32:47
问题 I am programming C++ using gcc on an obscure system called linux x86-64. I was hoping that may be there are a few folks out there who have used this same, specific system (and might also be able to help me understand what is a valid pointer on this system). I do not care to access the location pointed to by the pointer, just want to calculate it via pointer arithmetic. According to section 3.9.2 of the standard: A valid value of an object pointer type represents either the address of a byte

Can I use a category to override a method which is itself in category on the superclass?

£可爱£侵袭症+ 提交于 2019-12-24 14:28:36
问题 @interface MySuperclass : NSObject { } @end @interface MySuperclass (MyCategory) - (void)myMethod; @end @interface MySubclass : MySuperclass { } @end @interface MySubclass (MyOtherCategory) - (void)myMethod; @end Is it defined which implementation of -myMethod will be called? Kochan states in Programming in Objective-C that: If more than one category declares a method with the same name for the same class, it is not defined which method will be executed when invoked. But I am not sure whether

Declare, manipulate and access unaligned memory in C++ [closed]

纵然是瞬间 提交于 2019-12-24 10:49:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I recently posted a question about unaligned memory access, but given the answer, I am a little lost. I often hear that "aligned memory access is far more efficient than unaligned access", but I am actually not sure what is unaligned memory. Consequently: What is unaligned memory?

Struct pointer casts

天涯浪子 提交于 2019-12-24 04:32:12
问题 I'm trying to implement a linked list like this: typedef struct SLnode { void* item; void* next; } SLnode; typedef struct DLnode { void* item; void* next; struct DLnode* prev; } DLnode; typedef struct LinkedList { void* head; /*SLnode if doubly_linked is false, otherwise DLnode*/ void* tail; /* here too */ bool doubly_linked; } LinkedList; And I want to access it like this: void* llnode_at(const LinkedList* ll, size_t index) { size_t i; SLnode* current; current = ll->head; for(i = 0; i <

Struct pointer casts

风格不统一 提交于 2019-12-24 04:32:01
问题 I'm trying to implement a linked list like this: typedef struct SLnode { void* item; void* next; } SLnode; typedef struct DLnode { void* item; void* next; struct DLnode* prev; } DLnode; typedef struct LinkedList { void* head; /*SLnode if doubly_linked is false, otherwise DLnode*/ void* tail; /* here too */ bool doubly_linked; } LinkedList; And I want to access it like this: void* llnode_at(const LinkedList* ll, size_t index) { size_t i; SLnode* current; current = ll->head; for(i = 0; i <

Does the boost::hold_any constructor have undefined behavior?

依然范特西╮ 提交于 2019-12-24 02:21:31
问题 I looked through the boost::hold_any file and I found something what confuses me. if I consider the informations I got through the answers to my question: What happens if you call a destructor and use the allocated memory again for other objects? (In the answer by Mike Seymour) then it is "forbidden" to manipulate the memory of an object which weren't released and reallocated yet, to place there a new object of a different type. I always thought the boost library sticks to the standard, but