designated-initializer

What happens to fields not named by a designated initializer?

独自空忆成欢 提交于 2019-11-27 14:48:18
问题 In C99 (and not in C++), it's possible to initialize structs using this syntax: struct info { char name[8+1]; int sz; int typ; }; struct info arr[] = { [0] = { .sz = 20, .name = "abc" }, [9] = { .sz = -1, .name = "" } }; What happens to the unspecified fields? 回答1: They are zeroed. From the C99 standard §6.7.8 (Initialization)/21, If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to

What is a designated initializer in C?

喜夏-厌秋 提交于 2019-11-27 06:04:26
问题 I know this might be a basic question. I have an assignment that requires me to understand what designated initializers in C are and what it means to initialize a variable with one. I am not familiar with the term and couldn't find any conclusive definitions. What is a designated initializer in C? 回答1: Designated initialisers come in two flavours: 1) It provides a quick way of initialising specific elements in an array: int foo[10] = { [3] = 1, [5] = 2 }; will set all elements to foo to 0,

Why are designated initializers not implemented in g++

笑着哭i 提交于 2019-11-27 03:17:19
问题 Is there any specific reason why has support for designated initializers not been added to g++? Is the reason that C99 standards came late and g++ was developed earlier and later people didn't care about this issue, or there is some inherent difficulty in implementing designated initializers in the grammar of C++? 回答1: As I noted in a comment, G++ doesn't support C99 standard designated initialisers, but it does support the GNU extension to C90 which allows designated initialisers. So this

C++ Equivalent to Designated Initializers?

时间秒杀一切 提交于 2019-11-27 01:16:58
Recently I've been working on some embedded devices, where we have some structs and unions that need to be initialized at compile time so that we can keep certain things in flash or ROM that don't need to be modified, and save a little flash or SRAM at a bit of a performance cost. Currently the code compiles as valid C99, but without this adjustment it used to compile as C++ code as well, and it would be great to support things being compiled that way as well. One of the key things that prevents this is that we're using C99 designated initializers which do not work within the C subset of C++.

Swift - Must call a designated initializer of the superclass SKSpriteNode error

╄→尐↘猪︶ㄣ 提交于 2019-11-27 01:13:20
问题 This code worked on first XCode 6 Beta, but on latest Beta it's not working and gives such errors Must call a designated initializer of the superclass SKSpriteNode : import SpriteKit class Creature: SKSpriteNode { var isAlive:Bool = false { didSet { self.hidden = !isAlive } } var livingNeighbours:Int = 0 init() { // throws: must call a designated initializer of the superclass SKSpriteNode super.init(imageNamed:"bubble") self.hidden = true } init(texture: SKTexture!) { // throws: must call a

What does dot (.) mean in a struct initializer?

人盡茶涼 提交于 2019-11-26 14:12:24
static struct fuse_oprations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read, }; I don't understand this C syntax well. I can't even search because I don't know the syntax's name. What's that? This is a C99 feature that allows you to set specific fields of the struct by name in an initializer. Before this, the initializer needed to contain just the values, for all fields, in order -- which still works, of course. So for the following struct: struct demo_s { int first; int second; int third; }; ...you can use struct demo_s demo = { 1, 2,

C++ Equivalent to Designated Initializers?

♀尐吖头ヾ 提交于 2019-11-26 09:39:29
问题 Recently I\'ve been working on some embedded devices, where we have some structs and unions that need to be initialized at compile time so that we can keep certain things in flash or ROM that don\'t need to be modified, and save a little flash or SRAM at a bit of a performance cost. Currently the code compiles as valid C99, but without this adjustment it used to compile as C++ code as well, and it would be great to support things being compiled that way as well. One of the key things that