{"action":"created","issue":{"url":"https://api.github.com/repos/jameysharp/corrode/issues/38","repository_url":"https://api.github.com/repos/jameysharp/corrode","labels_url":"https://api.github.com/repos/jameysharp/corrode/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/jameysharp/corrode/issues/38/comments","events_url":"https://api.github.com/repos/jameysharp/corrode/issues/38/events","html_url":"https://github.com/jameysharp/corrode/pull/38","id":165431915,"number":38,"title":"Adding partial initialization of structs","user":{"login":"harpocrates","id":10766081,"avatar_url":"https://avatars.githubusercontent.com/u/10766081?v=3","gravatar_id":"","url":"https://api.github.com/users/harpocrates","html_url":"https://github.com/harpocrates","followers_url":"https://api.github.com/users/harpocrates/followers","following_url":"https://api.github.com/users/harpocrates/following{/other_user}","gists_url":"https://api.github.com/users/harpocrates/gists{/gist_id}","starred_url":"https://api.github.com/users/harpocrates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harpocrates/subscriptions","organizations_url":"https://api.github.com/users/harpocrates/orgs","repos_url":"https://api.github.com/users/harpocrates/repos","events_url":"https://api.github.com/users/harpocrates/events{/privacy}","received_events_url":"https://api.github.com/users/harpocrates/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2016-07-13T22:02:10Z","updated_at":"2016-07-29T06:18:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jameysharp/corrode/pulls/38","html_url":"https://github.com/jameysharp/corrode/pull/38","diff_url":"https://github.com/jameysharp/corrode/pull/38.diff","patch_url":"https://github.com/jameysharp/corrode/pull/38.patch"},"body":"To the best of my understanding of C99, this implements partial initialization ([previous discussion](https://github.com/jameysharp/corrode/pull/37)), dealing with zeroing and out of order fields.\r\n```c\r\nstruct grade {\r\n  float percentage;\r\n  int failing;\r\n};\r\nstruct student {\r\n  struct student *friends;\r\n  int age;\r\n  struct grade marks;\r\n};\r\n\r\nvoid f() {\r\n  struct student s;\r\n  s = (struct student) { };\r\n  s = (struct student) { .age = 9 };\r\n  s = (struct student) { .age = 9, { 0.45, 1 } };\r\n  s = (struct student) { .age = 9, { .percentage = 0.45, .failing = 1 } };\r\n  s = (struct student) { 0, 9, { 0.45, 1 } };\r\n  s = (struct student) { .marks = { 0.45, 1 }, .age = 9 };\r\n}\r\n```\r\ncompiles to\r\n```rust\r\n#[derive(Clone, Copy)]\r\n#[repr(C)]\r\npub struct grade {\r\n    pub percentage : f32,\r\n    pub failing : i32,\r\n}\r\n\r\n#[derive(Clone, Copy)]\r\n#[repr(C)]\r\npub struct student {\r\n    pub friends : *mut student,\r\n    pub age : i32,\r\n    pub marks : grade,\r\n}\r\n\r\n#[no_mangle]\r\npub unsafe fn f() {\r\n    let mut s : student;\r\n    s = student {\r\n            friends: 0 as (*mut student),\r\n            age: 0i32,\r\n            marks: grade { percentage: 0f32, failing: 0i32 }\r\n        };\r\n    s = student {\r\n            friends: 0 as (*mut student),\r\n            age: 9i32,\r\n            marks: grade { percentage: 0f32, failing: 0i32 }\r\n        };\r\n    s = student {\r\n            friends: 0 as (*mut student),\r\n            age: 9i32,\r\n            marks: grade { percentage: 0.45f64 as (f32), failing: 1i32 }\r\n        };\r\n    s = student {\r\n            friends: 0 as (*mut student),\r\n            age: 9i32,\r\n            marks: grade { percentage: 0.45f64 as (f32), failing: 1i32 }\r\n        };\r\n    s = student {\r\n            friends: 0i32 as (*mut student),\r\n            age: 9i32,\r\n            marks: grade { percentage: 0.45f64 as (f32), failing: 1i32 }\r\n        };\r\n    s = student {\r\n            friends: 0 as (*mut student),\r\n            age: 9i32,\r\n            marks: grade { percentage: 0.45f64 as (f32), failing: 1i32 }\r\n        };\r\n}\r\n```\r\nAnd code that has too many initializers or designators that do not correspond to fields or non-member designators is dealt with via `badSource`.\r\n\r\nOne thing that isn't clear to me from the C99 spec on initialization (6.7.8) - when does it make sense to have multiple designators for a given initializer? Seems like point 18 addresses this, and I think this means I am rejecting valid code, since I currently assume that an initializer can have at most one designator (and it must be a member designator)...\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jameysharp/corrode/issues/comments/236103419","html_url":"https://github.com/jameysharp/corrode/pull/38#issuecomment-236103419","issue_url":"https://api.github.com/repos/jameysharp/corrode/issues/38","id":236103419,"user":{"login":"harpocrates","id":10766081,"avatar_url":"https://avatars.githubusercontent.com/u/10766081?v=3","gravatar_id":"","url":"https://api.github.com/users/harpocrates","html_url":"https://github.com/harpocrates","followers_url":"https://api.github.com/users/harpocrates/followers","following_url":"https://api.github.com/users/harpocrates/following{/other_user}","gists_url":"https://api.github.com/users/harpocrates/gists{/gist_id}","starred_url":"https://api.github.com/users/harpocrates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harpocrates/subscriptions","organizations_url":"https://api.github.com/users/harpocrates/orgs","repos_url":"https://api.github.com/users/harpocrates/repos","events_url":"https://api.github.com/users/harpocrates/events{/privacy}","received_events_url":"https://api.github.com/users/harpocrates/received_events","type":"User","site_admin":false},"created_at":"2016-07-29T06:18:36Z","updated_at":"2016-07-29T06:18:36Z","body":"Haha, the edge case I'm fixing is the one in the previous comment concerning initializing a primitive versus a struct (and the different behavior of the current object in those cases) - I couldn't think of a better name for the commit. 😄 But yeah, I will definitely add more documentation in the code too; these last two commits were very tentative as I wasn't sure if they even had the desired behaviour.\r\n\r\nThat said, I'm also going to get to work on seeing if / how I can make the code look cleaner and more self-documenting too."}}
{"actor":{"display_login":"harpocrates"}}