struct

Memory layout differences in structs

巧了我就是萌 提交于 2019-12-23 09:57:17
问题 I have the following structure in C++ struct A { int a; double b; float c; } Is there a difference in memory layout between this struct and one with a function added to it? struct B { int a; double b; float c; void foo(); } B::foo() { //do stuff } 回答1: The C++ standard guarantees that memory layouts of a C struct and a C++ class (or struct -- same thing) will be identical, provided that the C++ class/struct fits the criteria of being POD ("Plain Old Data"). So what does POD mean? A class or

struct or class

*爱你&永不变心* 提交于 2019-12-23 09:40:53
问题 I'm developing an iPhone 3.1.3 application. I have a class, called Object2D , with fields and methods; which represent a shape. Object2D has a field that represents its size, and another field that represent its type. Now, I need another class called Pattern , which is a set of shapes. In Pattern I'm going to have an array of shapes. From these shapes I only need their size, their type and their location inside pattern, I don't need any method. I'm wondering it is better to have a new struct

How to dynamically create and read structs in C?

大兔子大兔子 提交于 2019-12-23 09:38:53
问题 How can I do something like that (just an example): any_struct *my_struct = create_struct(); add_struct_member(my_struct, "a", int_member); add_struct_member(my_struct, "b", float_member); So that I could load and use a struct instance "from the outside" (at the address addressOfMyStruct ) with the given structure here? any_struct_instance *instance = instance(my_struct, addressOfMyStruct); int a = instance_get_member(instance, "a"); float b = instance_get_member(instance, "b"); I would also

Array of structs in C#

淺唱寂寞╮ 提交于 2019-12-23 09:32:58
问题 I'm trying to get input from user using array of structs and then print it: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CA4 { class Program { static void Main(string[] args) { StudentDetails[,] student = new StudentDetails[5, 1]; Console.WriteLine("Please enter the unit code:"); student[0, 0].unitCode = Console.ReadLine(); Console.WriteLine("Please enter the unit number:"); student[1, 0].unitNumber = Console.ReadLine(); Console.WriteLine(

converting a struct to a json when querying athena

╄→гoц情女王★ 提交于 2019-12-23 09:25:38
问题 I have an athena table which I did not create or manage, but can query. one of the fields is a struct type. for the sake of the example let's suppose it looks like this: my_field struct<a:string, b:string, c:struct<d:string,e:string> > Now, I know how to query specific fields within this struct. But in one of my queries I need to extract the complete struct. so I just use: select my_field from my_table and the result looks like a string: {a=aaa, b=bbb, c={d=ddd, e=eee}} I want to get the

What is meaning of “:” in struct C [duplicate]

邮差的信 提交于 2019-12-23 09:07:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What does 'unsigned temp:3' means struct Test { unsigned a : 5; unsigned b : 2; unsigned c : 1; unsigned d : 5; }; Test B; printf("%u %u %u %u", B.a, B.b, B.c, B.d); // output: 0 0 0 0 static struct Test A = { 1, 2, 3, 4}; Could someone explain me what is purpose of : in struct, printf just outputs 0 so I assume these are not default values, but what they are then? Also could someone explain me why does A.a, A.b

Why does Assert.AreEqual on custom struct with implicit conversion operator fail?

不羁的心 提交于 2019-12-23 08:59:25
问题 I've created a custom struct to represent an amount. It is basically a wrapper around decimal . It has an implicit conversion operator to cast it back to decimal . In my unit test, I assert that the Amount equals the original decimal value, but the test fails. [TestMethod] public void AmountAndDecimal_AreEqual() { Amount amount = 1.5M; Assert.AreEqual(1.5M, amount); } When I use an int though (for which I did not create a conversion operator), the test does succeed. [TestMethod] public void

… with constructor not allowed in union problem

你。 提交于 2019-12-23 08:18:32
问题 I desperately need to find a solution for the following problem: namespace test { template <int param = 0> struct Flags { int _flags; Flags() { _flags = 0; } Flags(int flags) { _flags = flags; } void init() { } }; union example { struct { union { struct { Flags<4096> f; }p1; //error: member 'test::example::<anonymous struct>::<anonymous union>::<anonymous struct> test::example::<anonymous struct>::<anonymous union>::p1' with constructor not allowed in union struct { Flags<16384> ff; }p2; /

Conforming to Hashable protocol?

…衆ロ難τιáo~ 提交于 2019-12-23 07:21:54
问题 I'm trying to make a dictionary with the key as a struct I've created and the value as an array of Ints. However, I keep getting the error: Type 'DateStruct' does not conform to protocol 'Hashable' I'm pretty sure I've implemented the necessary methods but for some reason it still doesn't work. Here's my struct with the implemented protocols: struct DateStruct { var year: Int var month: Int var day: Int var hashValue: Int { return (year+month+day).hashValue } static func == (lhs: DateStruct,

marshal c struct to c#

做~自己de王妃 提交于 2019-12-23 05:46:09
问题 Does any body can marshal this part of c/c++ code in c# please? typedef struct { BYTE bCommandCode; BYTE bParameterCode; struct { DWORD dwSize; LPBYTE lpbBody; } Data; } COMMAND, *LPCOMMAND; thanks a lot 回答1: First off, declare the above struct as a managed struct - something like: [StructLayout(LayoutKind.Sequential)] struct SomeStruct { byte bCommandCode; byte bParameterCode; SomeOtherStruct otherStruct; Data Data; } struct SomeOtherStruct { uint dwSize; byte lpBody; } struct Data { }