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 `.offsetof` and 
computing the pointer manually.


I am using ```-BetterC```, so that path is closed to me, I 
think.


I believe you aren't allowed to _append_ to dynamic 
arrays/slices; otherwise you can use them


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 the pointer manually.


I am using ```-BetterC```, so that path is closed to me, I think.


dynamic arrays are really slices, and they are allowed in betterC.

-Steve


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 ```-BetterC```, so that path is closed to me, I think.




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

2022-08-19 Thread kinke via Digitalmars-d-learn

On Friday, 19 August 2022 at 13:49:08 UTC, 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.


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.


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 "member" is a macro in C. D doesn't have 
macros, so it uses properties.


Nope, it's really a dynamically sized struct with a last 
`CHAR[1]` member: 
https://docs.microsoft.com/en-us/windows/win32/api/setupapi/ns-setupapi-sp_device_interface_detail_data_a


Just like with C, these abominations need very special care, and 
regularly allocating on the stack or using as an aggregate field 
isn't possible.


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.


The error message could be better though.

-Steve


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 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.


"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 try this at https://run.dlang.io/, build with ```LDC```, 
with argument: ```-mtriple=x86_64-windows-msvc```.