designated-initializer

Possible compiler bug in MSVC12 (VS2013) with designated initializer

早过忘川 提交于 2019-12-18 05:44:13
问题 Using VS2013 Update 2, I've stumbled on some strange error message : // test.c int main(void) { struct foo { int i; float f; }; struct bar { unsigned u; struct foo foo; double d; }; struct foo some_foo = { .i = 1, .f = 2.0 }; struct bar some_bar = { .u = 3, // error C2440 : 'initializing' : cannot convert from 'foo' to 'int' .foo = some_foo, .d = 4.0 }; // Works fine some_bar.foo = some_foo; return 0; } Both GCC and Clang accept it. Am I missing something or does this piece of code exposes a

Possible compiler bug in MSVC12 (VS2013) with designated initializer

∥☆過路亽.° 提交于 2019-12-18 05:44:11
问题 Using VS2013 Update 2, I've stumbled on some strange error message : // test.c int main(void) { struct foo { int i; float f; }; struct bar { unsigned u; struct foo foo; double d; }; struct foo some_foo = { .i = 1, .f = 2.0 }; struct bar some_bar = { .u = 3, // error C2440 : 'initializing' : cannot convert from 'foo' to 'int' .foo = some_foo, .d = 4.0 }; // Works fine some_bar.foo = some_foo; return 0; } Both GCC and Clang accept it. Am I missing something or does this piece of code exposes a

Using Designated Initializers with the Heap

泄露秘密 提交于 2019-12-17 20:53:21
问题 One can use designated initializers as shown below (for "billy") without issue, but when the same initialization approach is used on dynamic memory things will break at compile-time. What are the restrictions for using designated initializers? Aside from where (i.e. the address) to which we are writing, what makes these two initializations different? Why can we not use designated initializers with dynamic memory? struct student{ char *name; int age; }; void print_student(struct student* st){

Using designated initializers with unnamed nested data types

戏子无情 提交于 2019-12-11 04:23:12
问题 I'm wondering if it is possible to use designated initializers in unnamed data members of structs... (Yikes, a mouthful, but yes, it is the cleanest way to do what I'm trying to do...). If I have: typedef struct MainStruct { union { uint8_t a8[16]; uint64_t a64[2]; }; uint64_t i64; } MainStruct_t; typedef struct OtherStruct { MainStruct_t main; int otherval; } OtherStruct_t; OtherStruct_t instance = { .main.a64 = { 0, 0 }, .otherval = 3 }; and I try to compile, I get the error: tst3.c:16:

How to resolve designated initialization error for UITableViewController?

喜夏-厌秋 提交于 2019-12-10 14:29:21
问题 I'm new to swift and I'm having problems declaring my initializer in my PlacesTableViewController class. It prompts me "Super.init isn't called before returning from initializer" and when I added the Super.init, it prompts me: "Must call a designated initializer of the superclass 'UITableViewController'" this is my PlacesTableViewController.swift file: class PlacesTableViewController: UITableViewController { var pa55DB : COpaquePointer = nil var selectStatement : COpaquePointer = nil; var

Cryptic struct definition in C

时光总嘲笑我的痴心妄想 提交于 2019-12-10 02:06:14
问题 I came across the following maze definition code: typedef struct mazeNode { int hasCheese; int tag; struct mazeNode *left; struct mazeNode *right; } maze_t; maze_t maze = { .tag = 1, .left = &(maze_t) { .left = &(maze_t) { .left = &(maze_t) {}, .right = &(maze_t) {} }, .right = &(maze_t) { .right = &(maze_t) {} } }, .right = &(maze_t) { .tag = 8, .left = &(maze_t) {}, .right = &(maze_t) { .tag = 10, .left = &(maze_t) { .tag = 11, .left = &(maze_t) { .hasCheese = 1, .tag = 12 } }, .right = &

Override designated initializer of superclass

限于喜欢 提交于 2019-12-09 09:48:03
问题 I am reading a book which has a guideline: "If a class declares a designated initializer that is different from its superclass, the superclass’s designated initializer must be overridden to call the new designated initializer" As I understand this guideline in other words is that, if I am subclassing my class form its superclass, and my subclass has a designated initializer which is different from des. initializer of its superclass, then in my subclass I must override the designated

C++20 designated initializers with templated types

岁酱吖の 提交于 2019-12-08 17:00:48
问题 How are designated initializers (C++20) supposed to work with CTAD? This code works fine in gcc9.2, but fails with clang8 template <typename int_t=int, typename float_t=float> struct my_pair { int_t first; float_t second; }; template<typename ... ts> my_pair(ts...) -> my_pair<ts...>; int main() { my_pair x{.first = 20, .second = 20.f}; static_assert( std::is_same_v<decltype(x.first), int> ); static_assert( std::is_same_v<decltype(x.second), float> ); } Is this supposed to be valid? See an

Why can't a designated initializer call a secondary initializer in its base class?

走远了吗. 提交于 2019-12-08 16:19:40
问题 According to the documentation, a class's designated initializer in Objective-C must call the designated initializer of its base class. Another rule is that secondary initializers must call the designated initializer of their own class. But if the second rule is followed, why can't a designated initializer call a secondary initializer in its base class? This base secondary initializer will ultimately call its own level's D.I., so the object will still be properly initialized, right? The

CTAD and designated initializers in C++20

只谈情不闲聊 提交于 2019-12-07 00:05:10
问题 I have already stated confusion about CTAD with designated initializers in this question, but i have another confusion with a very similar code snippet template <typename int_t=int, typename float_t=float> struct my_pair { int_t first; float_t second; }; template<typename ... ts> my_pair(ts...) -> my_pair<ts...>; int main() { my_pair x{.second = 20.f}; static_assert( std::is_same_v<decltype(x.first), int> ); //FAILS <- its deduced to float static_assert( std::is_same_v<decltype(x.second),