struct

Clarification about Bit-field ordering semantics in C

让人想犯罪 __ 提交于 2020-01-29 14:38:09
问题 I have troubles understanding the exact meaning of a paragraph of C99 draft standard (N1256) about bit-fields (6.7.2.1:10): 6.7.2.1 Structure and union specifiers [...] Semantics [...] An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit

Passing reference of packed struct member to template. gcc bug?

心已入冬 提交于 2020-01-29 05:15:08
问题 I encountered a problem, passing struct member to a template function. The function's goal is to take the address and size of the member. Here is simple example: This is the struct. It has packed attribute. struct TestStruct { unsigned char elem1; unsigned char elem2; uint64_t elem3; char buf[10000]; int elem4; unsigned char elem5; } __attribute__ ((packed)); this is the template function, which should get a member's address template<typename T> void addData(const T &val) { printf ("address

How to initialize a struct in C# [duplicate]

こ雲淡風輕ζ 提交于 2020-01-28 09:40:54
问题 This question already has answers here : C# Structs: Unassigned local variable? (2 answers) Closed 2 years ago . I have some code to initialize a struct in C#: namespace Practice { public struct Point { public int _x; public int _y; public int X { get { return _x; } set { _x = value; } } public int Y { get { return _y; } set { _y = value; } } public Point(int x, int y) { _x = x; _y = y; } } class Practice { public static void Main() { Point p1; p1.X = 1; p1.Y = 2; } } } The above code gives a

How to initialize a struct in C# [duplicate]

独自空忆成欢 提交于 2020-01-28 09:39:28
问题 This question already has answers here : C# Structs: Unassigned local variable? (2 answers) Closed 2 years ago . I have some code to initialize a struct in C#: namespace Practice { public struct Point { public int _x; public int _y; public int X { get { return _x; } set { _x = value; } } public int Y { get { return _y; } set { _y = value; } } public Point(int x, int y) { _x = x; _y = y; } } class Practice { public static void Main() { Point p1; p1.X = 1; p1.Y = 2; } } } The above code gives a

Unmarshal Json data in a specific struct

萝らか妹 提交于 2020-01-28 04:50:47
问题 I want to unmarshal the following JSON data in Go: b := []byte(`{"Asks": [[21, 1], [22, 1]] ,"Bids": [[20, 1], [19, 1]]}`) I know how to do that, i define a struct like this: type Message struct { Asks [][]float64 `json:"Bids"` Bids [][]float64 `json:"Asks"` } What i don't know is if there is a simple way to specialize this a bit more. I would like to have the data after the unmarshaling in a format like this: type Message struct { Asks []Order `json:"Bids"` Bids []Order `json:"Asks"` } type

Python - converting sock.recv to string

我的梦境 提交于 2020-01-27 07:49:07
问题 I'm digging around with python and networking. while True: data = sock.recv(10240) This is definitely listening. But it seems to need to be converted to a text string. I've seen some people using struct.unpack() , but I'm not sure exactly how it works. What's the way to convert? 回答1: What you get back from recv is a bytes string: Receive data from the socket. The return value is a bytes object representing the data received. In Python 3.x, to convert a bytes string into a Unicode text str

Python - converting sock.recv to string

元气小坏坏 提交于 2020-01-27 07:47:16
问题 I'm digging around with python and networking. while True: data = sock.recv(10240) This is definitely listening. But it seems to need to be converted to a text string. I've seen some people using struct.unpack() , but I'm not sure exactly how it works. What's the way to convert? 回答1: What you get back from recv is a bytes string: Receive data from the socket. The return value is a bytes object representing the data received. In Python 3.x, to convert a bytes string into a Unicode text str

Python - converting sock.recv to string

我与影子孤独终老i 提交于 2020-01-27 07:43:51
问题 I'm digging around with python and networking. while True: data = sock.recv(10240) This is definitely listening. But it seems to need to be converted to a text string. I've seen some people using struct.unpack() , but I'm not sure exactly how it works. What's the way to convert? 回答1: What you get back from recv is a bytes string: Receive data from the socket. The return value is a bytes object representing the data received. In Python 3.x, to convert a bytes string into a Unicode text str

Stucture values not staying, values changed to -858993460

混江龙づ霸主 提交于 2020-01-26 02:50:08
问题 I'm clearly doing something wrong or forgetting something. I have defined a structure in a header file with four variables. I then assign values to those variables in a function located in a different .cpp then I try and take the new values from the structure and assign to different variable in another function. Problem is, I'm able to assign values to the variables in the structure but when I try and transfer those values to other variables they become something like -858993460(this is

How do I create a custom struct to assign the contents of array into usable variables?

廉价感情. 提交于 2020-01-25 21:54:16
问题 I have a JSON function that previously mapped the contents of an array ( countries , divisions , teams (not shown)) into seperate variables using this code: let task = URLSession.shared.dataTask{ (response: URLResponse?, error: Error?) in DispatchQueue.main.async { if error != nil { print("error=\(error)") return } do{ let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String:AnyObject] print (json) if let arr = json?["countries"] as? [[String:String]] {