Re: Address of a class object

2023-01-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/4/23 2:27 PM, Ali Çehreli wrote: On 1/4/23 10:48, H. S. Teoh wrote: > Allocations are not necessarily consecutive; the GC may have its own > strategy of allocation that doesn't follow a linear sequence. That was one of my guesses. So, I put the objects into a 2-length static array but

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 13:43, H. S. Teoh wrote: > You do realize that the compiler is free to reorder local variables on > the stack, right? ;-) Of course. :) I was trying different strategies to catch the compiler (dmd here) in a single act of 8-byte object alignment as reported by .alignof. Another

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 11:27, Ali Çehreli wrote: > writeln("hidden 0: ", hiddenValue(addr, 0)); > writeln("hidden 1: ", hiddenValue(addr, 1)); Silly me! :) Those members have names: writeln("__vptr : ", obj.__vptr); writeln("__monitor : ", obj.__monitor);

Re: Address of a class object

2023-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 04, 2023 at 01:20:12PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/4/23 12:02, Steven Schveighoffer wrote: > > On 1/4/23 2:27 PM, Ali Çehreli wrote: > > >> I put the objects into a 2-length > >> static array but the difference was still 0x20. (?) > > > > Are you putting

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/23 20:01, Paul wrote: > Size Alignment Type > = >17 8 MyClass > > MyClassObj1 MyClassObj2 > 27727202000 27727202020 > ``` > If my size is 17 bytes and my alignment is 8 bytes, shouldn't my > MyClassObj2 in this example be @

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 12:02, Steven Schveighoffer wrote: > On 1/4/23 2:27 PM, Ali Çehreli wrote: >> I put the objects into a 2-length >> static array but the difference was still 0x20. (?) > > Are you putting the class *references* in a 2-length static array? I lied. As I could not put the objects in a

Re: Address of a class object

2023-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 04, 2023 at 09:51:05AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/3/23 20:01, Paul wrote: > > > Size Alignment Type > > = > >17 8 MyClass > > > > MyClassObj1 MyClassObj2 > > 27727202000 27727202020 > > ``` > > If my

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 10:48, H. S. Teoh wrote: > Allocations are not necessarily consecutive; the GC may have its own > strategy of allocation that doesn't follow a linear sequence. That was one of my guesses. So, I put the objects into a 2-length static array but the difference was still 0x20. (?) >

Re: Is there a way to enforce UFCS?

2023-01-04 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo,

Re: Address of a class object

2023-01-04 Thread Paul via Digitalmars-d-learn
(Again, there is no problem here; we are just learning.) Ali Do I have this much right? ```d import std.stdio, std.traits; class MyClass {char c;} void main() { auto MyInt = 1; writeln("The address of MyInt is : ",," (stack)"); auto MyClassVar1 = new MyClass();

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 20:04, Paul wrote: >> (Again, there is no problem here; we are just learning.) >> Ali > > Do I have this much right? > ..with this output? Looks good to me. While we're here, you can force the class objects to be on the stack as well: scope MyClassVar1 = new MyClass(); I

Re: Address of a class object

2023-01-04 Thread areYouSureAboutThat via Digitalmars-d-learn
On Thursday, 5 January 2023 at 04:04:39 UTC, Paul wrote: .. Do I have this much right? ... First, i would say, add @safe to your main. @safe void main() ... Then you will see you are treading on dangerous waters ;-) Second, to be sure your getting the correct results, it would be nice if

Re: Is there a way to enforce UFCS?

2023-01-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo, int value) { foo.bar = value; } void main() {