struct Questions

2

Solved

I have a C struct defined as: struct my_c_s { u_char *ptr; unsigned flag_a:1; unsigned flag_b:1; int some_num; } How would flag_a and flag_b be represented? #[repr(C)] pub struct my_rust_s ...
Ian asked 21/7, 2017 at 4:48

8

Solved

I have a question concerning type constructors within a Value type. This question was inspired by something that Jeffrey Richter wrote in CLR via C# 3rd ed, he says (on page 195 - chapter 8) that y...
Disharmonious asked 14/7, 2010 at 12:33

5

Solved

I am trying to copy a struct of type Big to type Small without explicitly creating a new struct of type Small with the same fields. I have tried searching for other similar problems such as this a...
Jestinejesting asked 19/9, 2019 at 8:31

6

Is there any way to prevent the default constructor of a struct to be called? I have several structs in my project and some of them I can not let the default constructor to be called at any circum...
Precursor asked 13/4, 2016 at 16:44

11

Solved

Previously, when I needed to store a number of related variables, I'd create a class. function Item(id, speaker, country) { this.id = id; this.speaker = speaker; this.country = country; } var my...
Partida asked 2/2, 2009 at 6:25

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

4

Solved

I like value semantics in Swift but I am worried about the performance of mutating functions. Suppose we have the following struct: struct Point { var x = 0.0 mutating func add(_ t:Double){ x +=...
Elea asked 23/2, 2017 at 16:5

7

Solved

I have two structures, with values that should compute a pondered average, like this simplified version: typedef struct { int v_move, v_read, v_suck, v_flush, v_nop, v_call; } values; typedef st...
Unemployment asked 2/4, 2011 at 17:0

3

Solved

I am struggling with deserializing a integer into a string struct field. The struct field is a string and is expected to be assignable from users of my library. That's why I want it to be a string,...
Knitted asked 30/8, 2017 at 19:37

5

Solved

I am curious to know, Is it possible to use array of bit fields? Like: struct st { unsigned int i[5]: 4; };
Axiomatic asked 29/1, 2017 at 6:56

1

I would like to define a struct, Env which optionally contains a (mutable) reference to another Env, called it's parent. In all applications it can be easily shown that the parent will outlive the ...
Korman asked 28/11, 2022 at 5:50

18

Solved

How can I print (to the console) the Id, Title, Name, etc. of this struct in Golang? type Project struct { Id int64 `json:"project_id"` Title string `json:"title"` Name strin...
Convalescence asked 1/7, 2014 at 13:57

2

Solved

Is it possible to require that a struct have a particular field as part of a trait? I am doing some web automation in Rust with the thirtyfour_sync crate. I want to write some traits with default i...
Potamic asked 29/6, 2021 at 2:31

17

Solved

I want to initialize a struct element, split in declaration and initialization. This is what I have: typedef struct MY_TYPE { bool flag; short int value; double stuff; } MY_TYPE; void function...
Antidepressant asked 1/12, 2008 at 13:13

8

Solved

So I've got a collection of structs (it's actually a WCF datacontract but I'm presuming this has no bearing here). List<OptionalExtra> OptionalExtras; OptionalExtra is a struct. public pa...
Ikeda asked 14/3, 2013 at 10:46

9

Solved

I have a slice of structs. type Config struct { Key string Value string } // I form a slice of the above struct var myconfig []Config // unmarshal a response body into the above slice if err ...
Decade asked 29/7, 2016 at 8:46

4

Solved

I defined my struct as: struct taxPayer{ char name[25]; long int socialSecNum; float taxRate; float income; float taxes; }; My main function contains: taxPayer citizen1, citizen2; citize...
Triceratops asked 4/5, 2016 at 1:10

12

Solved

how can I convert a string ipAddress (struct in_addr) and vice versa? and how do I turn in unsigned long ipAddress? thanks
Syncopate asked 16/3, 2011 at 16:2

14

Solved

I'm pretty sure this is possible, because I'm pretty sure I've seen it done. I think it is awesome, but I will gladly accept answers along the lines of "this is a terrible idea because ____". Say ...
Impatience asked 30/1, 2009 at 5:50

5

Solved

I have a struct type with a *int64 field. type SomeType struct { SomeField *int64 } At some point in my code, I want to declare a literal of this (say, when I know said value should be 0, or po...
Busload asked 8/6, 2015 at 18:21

5

Solved

What is the recommended way to declare a struct that contains an array, and then create a zero-initialized instance? Here is the struct: #[derive(Default)] struct Histogram { sum: u32, bins: [...
Rajiv asked 21/11, 2014 at 13:49

7

Anybody think there are advantages to using a class or struct to pass arguments ? Like instead of f(int,float,string) Have f(Args) Where Args is struct with int,float,string members. Advant...
Gaff asked 13/10, 2015 at 20:48

7

Solved

Consider a function which returns two values. We can write: // Using out: string MyFunction(string input, out int count) // Using Tuple class: Tuple<string, int> MyFunction(string inp...
Baca asked 17/6, 2011 at 6:1

5

Solved

I have four integers {a, b, c, d} that can have the following range of values: a - {0 or 1} (1 bit) b - {0 or 1} (1 bit) c - {0, 1, 2, ..., 7} (3 bits) d - {0, 1, 2, ..., 7} (3 bits) at first,...
Derickderide asked 14/3, 2011 at 17:53

6

Solved

I have the function below which accepts a bool pointer. I'm wondering if there is any notation which allows me to set the value of the is field to true in the struct literal; basically without to d...
Measly asked 2/3, 2015 at 19:31

© 2022 - 2024 — McMap. All rights reserved.