Sunday, February 28, 2021

Digest for comp.lang.c++@googlegroups.com - 3 updates in 2 topics

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Feb 28 11:39AM -0800

On 2/26/2021 10:00 PM, Marcel Mueller wrote:
> way to extract this offset, preferably as constexpr?
 
> I know that there are limitations when B is a virtual base of T. The
> offset is no longer defined in this case.
 
I have no idea if this will work for you, or if its even standard with
regard to the use of alignas for virtual base classes.
 
__________________________________
#include <iostream>
#include <cstdint>
#include <cassert>
 
 
#define ALIGN 128
 
 
struct alignas(ALIGN) base
{
int a;
char b;
long c;
 
base()
{
std::cout << "base::base() " << this << "\n";
}
 
virtual ~base()
{
std::cout << "base::~base() " << this << "\n";
}
 
std::uintptr_t base_this() { return (std::uintptr_t)this; }
};
 
 
struct alignas(ALIGN) foo : virtual public base
{
int d;
 
foo()
{
std::cout << "foo::foo() " << this << "\n";
 
std::uintptr_t dif = base_this() - (uintptr_t)this;
 
std::cout << "dif = " << dif << "\n";
 
assert(dif == ALIGN);
}
 
~foo()
{
std::cout << "foo::~foo() " << this << "\n";
}
};
 
int main()
{
{
foo f;
}
 
return 0;
}
 
__________________________________
 
 
I am getting:
 
base::base() 010FF680
foo::foo() 010FF600
dif = 128
foo::~foo() 010FF600
base::~base() 010FF680
 
 
dif should always equal the alignment. What do you get on your end?
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Feb 28 12:05PM -0800

On 2/28/2021 11:39 AM, Chris M. Thomasson wrote:
> foo::~foo() 010FF600
> base::~base() 010FF680
 
> dif should always equal the alignment. What do you get on your end?
 
My "rational" is that if we over align the the base class and the
derived class on a common alignment, then they should both share that
alignment.
olcott <NoOne@NoWhere.com>: Feb 28 01:08PM -0600

On 2/28/2021 11:20 AM, Mr Flibble wrote:
> Publish now please unless of course you only have snake oil, which seems
> to be the case.
 
> /Flibble
 
This instance of H_Hat() is proved to be decidable and all the code is
provided. This H_Hat() calls Simulate() that returns true whenever its
input halts.
 
 
int Simulate(u32 P, u32 I)
{
((void(*)(int))P)(I);
return 1;
}
 
 
// P has the machine address of H_Hat()
void H_Hat(u32 P)
{
u32 Input_Halts = Simulate(P, P);
if (Input_Halts)
HERE: goto HERE;
return;
}
 
 
_Simulate()
[00000478](01) 55 push ebp
[00000479](02) 8bec mov ebp,esp
[0000047b](03) 8b450c mov eax,[ebp+0c]
[0000047e](01) 50 push eax
[0000047f](03) ff5508 call dword [ebp+08]
[00000482](03) 83c404 add esp,+04
[00000485](05) b801000000 mov eax,00000001
[0000048a](01) 5d pop ebp
[0000048b](01) c3 ret
 
 
_H_Hat()
[00000858](01) 55 push ebp
[00000859](02) 8bec mov ebp,esp
[0000085b](01) 51 push ecx
[0000085c](03) 8b4508 mov eax,[ebp+08]
[0000085f](01) 50 push eax
[00000860](03) 8b4d08 mov ecx,[ebp+08]
[00000863](01) 51 push ecx
[00000864](05) e80ffcffff call 00000478
[00000869](03) 83c408 add esp,+08
[0000086c](03) 8945fc mov [ebp-04],eax
[0000086f](04) 837dfc00 cmp dword [ebp-04],+00
[00000873](02) 7402 jz 00000877
[00000875](02) ebfe jmp 00000875
[00000877](02) 8be5 mov esp,ebp
[00000879](01) 5d pop ebp
[0000087a](01) c3 ret
 
Because the execution trace shown below shows that H_Hat() invokes
Simulate() with the same data two times in sequence we can conclude that
H_Hat() is invoked in infinite recursion.
 
Push instructions have already pushed the value shown in their in the
third column. The two push instructions preceding the call to Simulate()
are its second and first parameters respectively.
 
Columns
(1) Machine address of instruction
(2) Machine address of top of stack
(3) Value of top of stack after instruction executed
(4) Number of bytes of machine code
(5) Machine language bytes
(6) Assembly language text
 
...[00000858][000111c5][000111d1](01) 55 push ebp
...[00000859][000111c5][000111d1](02) 8bec mov ebp,esp
...[0000085b][000111c1][00000000](01) 51 push ecx
...[0000085c][000111c1][00000000](03) 8b4508 mov eax,[ebp+08]
...[0000085f][000111bd][00000858](01) 50 push eax
...[00000860][000111bd][00000858](03) 8b4d08 mov ecx,[ebp+08]
...[00000863][000111b9][00000858](01) 51 push ecx
; Call Simulate(0x858, 0x858);
...[00000864][000111b5][00000869](05) e80ffcffff call 00000478
...[00000858][000111a5][000111b1](01) 55 push ebp
...[00000859][000111a5][000111b1](02) 8bec mov ebp,esp
...[0000085b][000111a1][00000858](01) 51 push ecx
...[0000085c][000111a1][00000858](03) 8b4508 mov eax,[ebp+08]
...[0000085f][0001119d][00000858](01) 50 push eax
...[00000860][0001119d][00000858](03) 8b4d08 mov ecx,[ebp+08]
...[00000863][00011199][00000858](01) 51 push ecx
; Call Simulate(0x858, 0x858);
...[00000864][00011195][00000869](05) e80ffcffff call 00000478
 
 
 
--
Copyright 2021 Pete Olcott
 
"Great spirits have always encountered violent opposition from mediocre
minds." Einstein
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: