Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 27, 2014 Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Why wont the following code compile? import std.stdio; void main() { myStruct[] mystructs = { {1, 1.1f}, {2, 2.2f} }; } extern(C){ struct myStruct{ int x; float y; } } It fails with the (unhelpful imo) error message: source/app.d(7): Error: a struct is not a valid initializer for a myStruct[] The reason I need a C struct is because I'm interfacing to a C library that expects an array of myStructs. |
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Colin Grogan | On Monday, 27 January 2014 at 09:06:17 UTC, Colin Grogan wrote:
> Why wont the following code compile?
>
> import std.stdio;
>
> void main()
> {
> myStruct[] mystructs = {
> {1, 1.1f},
> {2, 2.2f}
> };
> }
>
> extern(C){
> struct myStruct{
> int x;
> float y;
> }
> }
>
> It fails with the (unhelpful imo) error message:
> source/app.d(7): Error: a struct is not a valid initializer for a myStruct[]
>
> The reason I need a C struct is because I'm interfacing to a C library that expects an array of myStructs.
myStruct[] mystructs = [
{1, 1.1f},
{2, 2.2f}
];
Arrays are enclosed in [] ;)
|
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote:
> On Monday, 27 January 2014 at 09:06:17 UTC, Colin Grogan wrote:
>> Why wont the following code compile?
>>
>> import std.stdio;
>>
>> void main()
>> {
>> myStruct[] mystructs = {
>> {1, 1.1f},
>> {2, 2.2f}
>> };
>> }
>>
>> extern(C){
>> struct myStruct{
>> int x;
>> float y;
>> }
>> }
>>
>> It fails with the (unhelpful imo) error message:
>> source/app.d(7): Error: a struct is not a valid initializer for a myStruct[]
>>
>> The reason I need a C struct is because I'm interfacing to a C library that expects an array of myStructs.
>
> myStruct[] mystructs = [
> {1, 1.1f},
> {2, 2.2f}
> ];
>
> Arrays are enclosed in [] ;)
I'm an idiot.
Can I delete this thread to save further embarrassment? :)
|
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Colin Grogan | On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote:
>>
>> Arrays are enclosed in [] ;)
>
> I'm an idiot.
> Can I delete this thread to save further embarrassment? :)
No! Evenryone will see this! >:E~
|
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Colin Grogan | On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote:
> On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote:
>> Arrays are enclosed in [] ;)
>
> I'm an idiot.
> Can I delete this thread to save further embarrassment? :)
HA-HA!
(read it with Nelson voice, ofc)
|
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Francesco Cattoglio | On Monday, 27 January 2014 at 10:39:28 UTC, Francesco Cattoglio wrote:
> On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote:
>> On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote:
>>> Arrays are enclosed in [] ;)
>>
>> I'm an idiot.
>> Can I delete this thread to save further embarrassment? :)
>
> HA-HA!
>
> (read it with Nelson voice, ofc)
In my defense, I believe C initializes arrays with the curly brackets....
Can I keep making excuses?
|
January 27, 2014 Re: Creating an array of C structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Colin Grogan | On Monday, 27 January 2014 at 13:08:28 UTC, Colin Grogan wrote:
> In my defense, I believe C initializes arrays with the curly brackets....
> Can I keep making excuses?
Yes you can... And don't worry, I mess up initialization too. Lots of time.
Especially when I tried initializing an array of structs made of 2 structs.
I think I wasted at least 15 minutes before giving up :D
|
Copyright © 1999-2021 by the D Language Foundation