designated-initializer

Why has Clang decided to allow designated initializers in C++?

拟墨画扇 提交于 2021-02-10 12:31:27
问题 I thought that designated initializers were discontinued in C++ and only worked in C. However, I came across a simple example which compiled and worked fine with clang++. int main() { int a[6] = { [4] = 29, [2] = 15 }; } g++: https://rextester.com/AXIZ79197 (Error) clang++: https://rextester.com/UYVHHP56966 (Works) vc++: https://rextester.com/UCBEU10658 (Error) Both g++ and vc++ failed to compile whereas clang++ worked just fine. It is also worth mentioning that g++ and vc++ gave different

Using a designated initializer to initialize nested struct with a `char []` member

喜你入骨 提交于 2020-03-22 08:42:33
问题 I have the following nested struct definition: typedef struct { int count; float cash; char item[50];//switch between array and pointer for testing initializers //char *item; }Purchase; typedef struct { int accnt; char acct_name[50]; Purchase purch; } Acct; Where for the Purchase struct by itself, the following initializer works: //Uses member names: /* 1 */Purchase p = {.count = 4, .cash = 12.56, .item = "thing"}; // Note: this member: ^^^^^^^^^^^^^^^ And for the nested struct Acct the

Embedded C++ static initialization of struct arrays

房东的猫 提交于 2020-01-25 06:48:10
问题 While migrating to C++ I require a certain function that seems to have been deprecated. sorry, unimplemented: non-trivial designated initializers not supported What is the correct way to implement the following data storage system in C++ for memory constraint systems? typedef union union_t { float f; int i; } arg; typedef struct type_t { int a; arg b; int d; } element; const element list[] = { { .a = 1, .b = { .f = 3.141519f }, .d = 6 }, { .a = 3, .b = { .i = 1 }, } }; Often the use of std

Check designated initializer in xcode

若如初见. 提交于 2020-01-17 06:01:59
问题 Is there any way to find out which initializer is the designated one in super class in Xcode? I type super().init.. then, Xcode shows all initializers of superclass. I want to know is there any sign or symbol to point out which is the designated one? Also a quick question. A designated initializer(DI) in subclass is allowed to only call a convenience initializer(CI) in superclass since the CI in superclass will eventually call the DI in superclass. Correct me if I'm wrong, thanks. 回答1: In

Non-designated initialiser inheritance from Objective C classes

守給你的承諾、 提交于 2020-01-02 11:20:12
问题 Having come across problems when sub-classing UIKit classes and adding immutable variables to them, I made a test project to figure out what was going on. My conclusion is that if: we have an Objective C class, which inherits from another class, with its own designated initialiser (implicit or explicitly annotated) in its initialiser , it calls [self initWithXX] where initWithXX is an init method on the superclass we subclass this class in Swift , adding an immutable property (which obviously

Is there a Way to Get Warned about Misbehaving Designated Initializers?

混江龙づ霸主 提交于 2019-12-30 10:56:09
问题 C99 introduced the concept of designated intializers for structs. So for example, given: typedef struct { int c; char a; float b; } X; I could initialize like: X foo = {.a = '\1', .b = 2.0F, .c = 4}; and calling: printf("c = %d\na = %hhu\nb = %f", foo.c, foo.a, foo.b); would output: c = 4 a = 1 b = 2.000000 As mentioned here this has the "surprising behavior" of assigning to c then a then b , independent of the order of my designated initializers. This becomes a real issue if I have functions

Initialization of a custom UIView in a UIViewController using a storyboard

雨燕双飞 提交于 2019-12-25 02:47:57
问题 I have a custom UIViewcontroller and wanted to initialize and assign a custom UIView which I assigned to an IBOutlet before. I'm using a storyboard. Can anybody give me hints where to call the designated initializer of the custom UIView? **MyCustomUIView.h** @interface MyCustomUIView : UIView @end **MyCustomUIView.m** @implementation MyCustomUIView - (id)initWithNumberOfHeaderRows:(NSUInteger)headerRowCount numberOfHeaderColumns:(NSUInteger)headerColumnCount frame:(CGRect)frame { self =

C99 Designated Initializer duplicate index not flagged at all in build output or lint

倖福魔咒の 提交于 2019-12-23 18:23:24
问题 I played around with designated initializers a bit the other day and noticed, to my surprise, that it is valid to use the same index more than once. What's more, it didn't even produce a compiler warning, error, or even informational statement when I did so, and even PC-Lint didn't seem to care (which I think surprised me the most). I'm wondering if there's a reason for compilers not even providing an information message in this case or if there are additional compiler/lint/etc. options that

-Wmissing-field-initializer when using designated initializers

别来无恙 提交于 2019-12-18 08:47:43
问题 I'm using GCC 4.6.2 (Mingw) and compiling with -Wextra . I'm getting strange warnings whenever I use designated initializers. For the following code typedef struct { int x; int y; } struct1; typedef struct { int x; int y; } struct2; typedef struct { struct1 s1; struct2 s2[4]; } bug_struct; bug_struct bug_struct1 = { .s1.x = 1, .s1.y = 2, .s2[0].x = 1, .s2[0].y = 2, .s2[1].x = 1, .s2[1].y = 2, .s2[2].x = 1, .s2[2].y = 2, .s2[3].x = 1, .s2[3].y = 2, }; I get warnings bug.c:24:3: warning: