offsetof + foreach

2012-09-07 Thread Ellery Newcomer
I have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s@: %s", _t.stringof, _t.offsetof); } complains Error: undefined identifier 'offsetof' what should I be doing?

Re: offsetof

2008-11-07 Thread Tim M
t; It's actually exactly the opposite from how it's defined in the spec: > you > can only use offsetof on instances of user-defined types, not on the > type > itself. > > It makes _absolutely_ no sense, I know. I can't help but feel it's a > bug, >

Re: offsetof

2008-11-07 Thread Jarrett Billingsley
On Fri, Nov 7, 2008 at 8:59 PM, Tim M <[EMAIL PROTECTED]> wrote: > Did you find a sollution? I need to get the offset of a member of a struct > so I can port a .h to a .di but dmd complains that the member doesn't exist > on the struct. I dont think anyone has ever tried the code at: > http://www.d

Re: offsetof

2008-11-07 Thread Tim M
I tried 1.036 and had the same problem. I'm using the offsetof and sizeof in a few constants which I've defined at the beginning of the file so I tried moving to the end of the file and it is no longer in error. I read somewhere that you don't have to forward declare everythin

Re: offsetof

2008-11-07 Thread Jarrett Billingsley
On Fri, Nov 7, 2008 at 11:38 PM, Tim M <[EMAIL PROTECTED]> wrote: > I tried 1.036 and had the same problem. I'm using the offsetof and sizeof in > a few constants which I've defined at the beginning of the file so I tried > moving to the end of the file and it is n

Re: offsetof + foreach

2012-09-07 Thread Ellery Newcomer
On 09/07/2012 10:31 AM, Ellery Newcomer wrote: I have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s@: %s", _t.stringof, _t.offsetof); } complains Error: undefined identifier 'offs

Re: offsetof + foreach

2012-09-08 Thread Kenji Hara
On Friday, 7 September 2012 at 17:32:43 UTC, Ellery Newcomer wrote: On 09/07/2012 10:31 AM, Ellery Newcomer wrote: I have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s@: %s", _t.string

Bug with offsetof?

2012-11-25 Thread Geancarlo
Error: this for x needs to be type TestStruct not type main.TestClass Is this a known bug? How can I work around this issue in order to use offsetof from a class function that is not static? Thanks

Re: Bug with offsetof?

2012-11-25 Thread Geancarlo
This also works fine: void test3() { TestStruct dummy; writeln(dummy.x.offsetof); }

Re: Bug with offsetof?

2012-11-25 Thread jerro
This works for me if I add parentheses to the line where you get the error like this: writeln(TestStruct().x.offsetof);//bug here The error you were getting is not related to offsetof. The problem seems to be that if you write TestStruct.x inside a non-static method, the compiler thinks you

Re: Bug with offsetof?

2012-11-25 Thread Ali Çehreli
n bug? How can I work around this issue in order to use offsetof from a class function that is not static? Thanks I don't know whether that is a bug but the class page at http://dlang.org/class.html says ".offsetof can only be applied to expressions which produce the type of the fi

Re: Bug with offsetof?

2012-11-25 Thread Geancarlo
Thanks jerro and Ali, I see your points. I thought offsetof was like C/C++'s sizeof... Guess while taking a crash course at a new language I will often bump into issues because I haven't read a specific doc.

Re: Bug with offsetof?

2012-11-25 Thread Jacob Carlborg
On 2012-11-26 05:49, Geancarlo wrote: Thanks jerro and Ali, I see your points. I thought offsetof was like C/C++'s sizeof... Guess while taking a crash course at a new language I will often bump into issues because I haven't read a specific doc. You do have .sizeof in D as well.

Re: Bug with offsetof?

2012-11-25 Thread Jacob Carlborg
On 2012-11-26 05:03, jerro wrote: This works for me if I add parentheses to the line where you get the error like this: writeln(TestStruct().x.offsetof);//bug here This will create an instance of TestStruct. -- /Jacob Carlborg

Re: Bug with offsetof?

2012-11-26 Thread Dan
On Monday, 26 November 2012 at 03:23:42 UTC, Geancarlo wrote: Hello, I'm using DMD32 D Compiler v2.060 for on Windows. writeln(TestStruct.x.offsetof);//bug here This works without creating your own instance: writeln(TestStruct.init.x.offsetof); Thanks Dan

Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
Cannot get the offset of static members of a struct struct X { __gshared public: int x; } X.x.offsetof < invalid. We can clearly get a pointer to the static struct X since &X.x is effectively the address of X(regardless nomenclature and terminology issues in D trying to hide this

Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
Cannot get the offset of static members of a struct struct X { __gshared public: int x; } X.x.offsetof < invalid. We can clearly get a pointer to the static struct X since &X.x is effectively the address of X(regardless nomenclature and terminology issues in D trying to hide this

Re: Why no offsetof for static struct?

2017-07-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 10 July 2017 at 20:01:39 UTC, FoxyBrown wrote: Cannot get the offset of static members of a struct That's because static members do not have an offset. They are not part of the struct in memory, just in name. We can clearly get a pointer to the static struct X There's barely an

Re: Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: On Monday, 10 July 2017 at 20:01:39 UTC, FoxyBrown wrote: Cannot get the offset of static members of a struct That's because static members do not have an offset. They are not part of the struct in memory, just in name. We can c

Re: Why no offsetof for static struct?

2017-07-10 Thread Ali Çehreli via Digitalmars-d-learn
On 07/10/2017 02:14 PM, FoxyBrown wrote: > On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: >> On Monday, 10 July 2017 at 20:01:39 UTC, FoxyBrown wrote: >>> Cannot get the offset of static members of a struct >> >> That's because static members do not have an offset. They are not part

Re: Why no offsetof for static struct?

2017-07-10 Thread Mike Parker via Digitalmars-d-learn
On 7/11/2017 6:14 AM, FoxyBrown wrote: On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: No, it isn't. Static members are stored in an entirely different place than non-static members. They are really just global variables in memory with their in-source name being nested somewhere

Re: Why no offsetof for static struct?

2017-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 11:14 PM, FoxyBrown wrote: auto GetStaticAddress(T)() { mixin("auto p = cast(T*)&T."~__traits(allMembers, T)[0]~";"); return p; } Returns the address of a struct's static members. No, it returns the address of T's first member. It's pretty obvious, the compiler seems

"Error: no property `offsetof` for type `char*`"

2022-08-19 Thread MyNameHere via Digitalmars-d-learn
I am receiving this error: ``` Error: no property `offsetof` for type `char*` ``` from this snippet: ```d import core.sys.windows.setupapi; void main() { SP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetail; uint Offset = DeviceInterfaceDetail.DevicePath.offsetof; } ``` You may

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread kinke via Digitalmars-d-learn
It's a method returning a `CHAR*` - `_DevicePath` is the actual member. I guess it's a dynamically sized struct, which cannot be mapped directly to D, hence this representation.

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread MyNameHere via Digitalmars-d-learn
Thank you, that seems to have resolved the issue, though I wish these sorts of problems would stop cropping up, they are souring the experience with the language.

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/19/22 9:49 AM, MyNameHere wrote: Thank you, that seems to have resolved the issue, though I wish these sorts of problems would stop cropping up, they are souring the experience with the language. Most likely that "member" is a macro in C. D doesn't have macros, so it uses properties. T

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread kinke via Digitalmars-d-learn
On Friday, 19 August 2022 at 14:22:04 UTC, Steven Schveighoffer wrote: On 8/19/22 9:49 AM, MyNameHere wrote: Thank you, that seems to have resolved the issue, though I wish these sorts of problems would stop cropping up, they are souring the experience with the language. Most likely that "mem

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread kinke via Digitalmars-d-learn
the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.offsetof` and computing the pointer manually.

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread MyNameHere via Digitalmars-d-learn
On Friday, 19 August 2022 at 14:30:50 UTC, kinke wrote: Oh and `DevicePath()` is a convenience member returning a pointer to the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.offsetof` and computing the pointer manually. I am using `

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/19/22 12:36 PM, MyNameHere wrote: On Friday, 19 August 2022 at 14:30:50 UTC, kinke wrote: Oh and `DevicePath()` is a convenience member returning a pointer to the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.offsetof` and computing t

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Tejas via Digitalmars-d-learn
On Friday, 19 August 2022 at 16:36:24 UTC, MyNameHere wrote: On Friday, 19 August 2022 at 14:30:50 UTC, kinke wrote: Oh and `DevicePath()` is a convenience member returning a pointer to the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.off