digitalmars.D.learn - Creating an array of C structs
- Colin Grogan (20/20) Jan 27 2014 Why wont the following code compile?
- Namespace (6/26) Jan 27 2014 myStruct[] mystructs = [
- Colin Grogan (3/34) Jan 27 2014 I'm an idiot.
- Stanislav Blinov (2/6) Jan 27 2014 No! Evenryone will see this! >:E~
- Francesco Cattoglio (3/7) Jan 27 2014 HA-HA!
- Colin Grogan (5/13) Jan 27 2014 In my defense, I believe C initializes arrays with the curly
- Francesco Cattoglio (6/9) Jan 27 2014 Yes you can... And don't worry, I mess up initialization too.
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.
Jan 27 2014
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 [] ;)
Jan 27 2014
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:I'm an idiot. Can I delete this thread to save further embarrassment? :)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 [] ;)
Jan 27 2014
On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote:No! Evenryone will see this! >:E~Arrays are enclosed in [] ;)I'm an idiot. Can I delete this thread to save further embarrassment? :)
Jan 27 2014
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:HA-HA! (read it with Nelson voice, ofc)Arrays are enclosed in [] ;)I'm an idiot. Can I delete this thread to save further embarrassment? :)
Jan 27 2014
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:In my defense, I believe C initializes arrays with the curly brackets.... Can I keep making excuses?On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote:HA-HA! (read it with Nelson voice, ofc)Arrays are enclosed in [] ;)I'm an idiot. Can I delete this thread to save further embarrassment? :)
Jan 27 2014
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
Jan 27 2014