designated-initializer Questions
4
Solved
Generally, in order to initialize a struct in c, we could only specify part of the fields. Like below:
static struct fuse_operations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_rea...
Mouflon asked 25/8, 2012 at 13:7
2
Solved
Consider the following code:
struct Foo{
std::string s1;
std::string s2;
};
int main(){
Foo f{.s1 = "s1", .s2 = f.s1 + "s2"};
std::cout << "s1='" << f...
Iago asked 3/11, 2023 at 11:13
3
Solved
I have an assignment that requires me to understand what are designated initializers in C, and what it means to initialize a variable with one.
I am not familiar with the term and couldn't find any...
Conch asked 9/11, 2017 at 13:3
1
Solved
Background information about what inspired my question:
I learned about Designated Initializers in C (see here and here: https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html), which are awesome...
Laoag asked 27/1, 2022 at 4:8
2
Solved
I have an aggregate structure B derived from another aggregate A. I would like to initialize it and there are two options: ordinary aggregate initialization and C++20 designated initializers:
struc...
Diversiform asked 7/8, 2021 at 19:25
2
Solved
In the following program, aggregate struct B has the field a, which is itself an aggregate. Can C++20 designated initializer be used to set its value without surrounding curly braces?
struct A { in...
Rebane asked 6/8, 2021 at 20:45
1
Solved
Consider the following code:
struct A{
int x;
int y;
};
struct B{
int y;
int x;
};
void func (A){
}
void func (B){
}
int main()
{
func({.y=1,.x=1});
}
For some reason both clang and gcc con...
Sift asked 28/5, 2021 at 19:25
2
Solved
While I was reading C++ reference, I had a question about this paragraph:
Note: out-of-order designated initialization, nested designated
initialization, mixing of designated initializers and r...
Sematic asked 11/11, 2018 at 15:53
1
Solved
When using aggregate / designated initialization of a struct it is possible to refer to another field like this:
#include <stdio.h>
int main()
{
struct
{
int a;
int b;
}
s =
{
.a =...
Swifter asked 12/11, 2020 at 19:1
2
Solved
C++ has a nice new feature:
struct Point{
int x;
int y;
int z;
};
Point p{.x=47, .y=1701, .z=0};
But if I add a constructor then I am forbidden from using the nice designated initalizers syntax:...
Corelative asked 10/11, 2020 at 13:48
8
I am unable to add init method to the following UIViewController class. I need to write some code in the init method. Do i have to write init(coder) method? Even when I add the coder and decoder me...
Doxy asked 6/6, 2015 at 5:6
4
Solved
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 ...
Swadeshi asked 8/11, 2011 at 7:38
2
Solved
Compiling with gcc -std=c99 -Wextra this piece of code:
#include <stdio.h>
struct T {
int a;
int *b;
int c;
};
int main(void)
{
struct T t = {.b = ((int []){1, 1})};
printf("%d\n", t...
Crew asked 3/3, 2018 at 6:53
1
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 Ob...
Mohock asked 1/7, 2015 at 12:20
2
Solved
I've got a question about one of the c++20 feature, designated initializers (more info about this feature here)
#include <iostream>
constexpr unsigned DEFAULT_SALARY {10000};
struct Person...
Jacksnipe asked 15/11, 2019 at 11:22
1
Solved
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 fl...
Thema asked 11/9, 2019 at 9:58
1
Solved
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_pai...
Tambac asked 11/9, 2019 at 9:48
6
Solved
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...
Lajoie asked 4/2, 2011 at 17:5
2
Solved
For a while now, one has been able to use "designated initializer" in GCC:
struct CC{
double a_;
double b_;
};
CC cc{.a_ = 1., .b_ = 2.}; assert(cc.a_ == 1. and cc.b_ == 2.); // ok
CC ...
Auston asked 11/9, 2018 at 18:39
2
Solved
Here, I have initialized array like this :
#include <stdio.h>
int main()
{
int a[10] = {1, 2, 3, [7] = 4, 8, 9};
printf("a[7] = %d\na[8] = %d\na[9] = %d\n", a[7], a[8], a[9]);
return ...
Moncada asked 14/9, 2017 at 16:54
2
Solved
I'm trying to create a simple Swift subclass of UIBarButtonItem:
class LabelBarButtonItem: UIBarButtonItem {
let label: UILabel
init(text: String) {
self.label = UILabel(frame: CGRectZero)
se...
Cadmann asked 24/11, 2014 at 22:47
1
Solved
I was creating my own custom tableViewCell and then I got an error saying:
'required' initializer 'init(coder:)' must be provided by subclass of
'UITableViewCell'
I looked it up and obviously it'...
Wirth asked 11/1, 2017 at 17:12
2
In post Using initWithNibName changes absolutely nothing, he shows two uses of the same View Nib definition, in the first case, he simply calls alloc/init and the second, he specifies initWithNibNa...
Crosshead asked 26/5, 2011 at 1:6
2
Solved
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...
Deandeana asked 16/2, 2016 at 15:30
2
Solved
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, ...
Crystallization asked 5/1, 2016 at 14:39
1 Next >
© 2022 - 2025 — McMap. All rights reserved.