struct

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

◇◆丶佛笑我妖孽 提交于 2020-01-25 21:53:23
问题 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]] {

C++ struct/union into C# struct

你说的曾经没有我的故事 提交于 2020-01-25 21:37:10
问题 How do I convert this struct/union from C++ code into my C#-UWP-code? The important thing is, that the logic and references does not change because this struct must be sent to a server. the difference to this article ( Convert C++ struct to C# ) i have got nonprimitive datatypes (as another struct and long[]) in my struct i have got unions in my struct typedef struct _HEADER { _HEADER_TYPE HeaderType; ULONG cc; union { struct { LONG Protocol; _TYPE CType; _INFO InfoDesired; // -> that's

Absolute fastest (and hopefully elegant) way to return a certain char buffer given a struct type

社会主义新天地 提交于 2020-01-25 21:25:14
问题 OK first and foremost, performance is most important here so I doubt a map would work. I have a list of structs (about 16 of them) like struct A { ... }; struct B { ... }; ... each are different and each are of different sizes. I'm wondering what elegant way we might be able to do something along the lines of: char BufferA[sizeof(struct A)]; char BufferB[sizeof(struct B)]; then write some method or mapping to return BufferA if you are working with struct A. Speed is definitely the most

Segmentation Error in C program When Run

≯℡__Kan透↙ 提交于 2020-01-25 21:01:09
问题 I've tried malloc , and no malloc and it will build but not run or compile. When I run the code on codepad.org it gives me a segmentation error. I have an array of structures I'm inputting and I'm searching through them for a specific item. That's as far as I got and no compile. The code is as follows (I used netbeans, codeblocks, and visual basic 2012 programs): #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 20 #define BLOODTYPESIZE 4 #define MAX 120000 typedef

String compare in Struct (Matlab)

China☆狼群 提交于 2020-01-25 10:30:06
问题 I need search a large struct and find the index of all the components with the same name. For example: If the name is 13hy I need an array [1,5] returned structure(1,1).name = '13hy' structure(2,1).name = '64hy' structure(3,1).name = '37hy' structure(4,1).name = '07hy' structure(5,1).name = '13hy' I have tried: strcmp(structure.name,'13hy') ismember(structure.name,'13hy') strfind(structure.name,'13hy') and I keep getting the error 'Too many input arguments.' Please help 回答1: Use arrayfun to

C# is there a difference between passing a struct reference and a class reference to a method in terms of speed?

房东的猫 提交于 2020-01-25 09:23:07
问题 As seen here, structs are passed by copy and classes by reference. But why is passing a struct by reference using the ref keyword still slower than passing a reference to a class ? I got different speeds for my program by replacing the struct keywords with class . All of the variables were already passed with the ref keyword. By changing keywords, I got 20% speed increase in my tests. Shoudn't the speed remain the same since I was already passing by reference ? What am I not understanding ?

problem in create packet using struct in c

折月煮酒 提交于 2020-01-25 07:57:10
问题 I wrote a c program that listen to 443 port and receives ssl packets : #include <errno.h> #include <ctype.h> #include <limits.h> #include <string.h> #include <stdlib.h> #include <arpa/inet.h> #include <netinet/in.h> #include <sys/stat.h> #include <stdio.h> #define MAX_SIZE 10000 struct ssl_header { uint8_t type; uint16_t version; uint16_t length; }; struct handshake { struct ssl_header hdr; uint8_t type; unsigned int length[3]; unsigned int ssl_version[2]; char random[32]; }; void *message

Struct not being populated

北城以北 提交于 2020-01-25 07:30:08
问题 I have a struct called Item and wish to populate its variables. struct Item { var title: String var others: [String] } Programs is an array of all the Item ’s created. var Programs = [Item]() I created a struct Item by the following: var entered = Item(title: hello1, others: ["hello2"]) The problem is that when I go to print the list of Items , the programs array is empty print(Programs) 回答1: You need to append it print("Before :",programs) let entered = Item(title: hello1, others: ["hello2"]

Embedded C++ static initialization of struct arrays

房东的猫 提交于 2020-01-25 06:48:10
问题 While migrating to C++ I require a certain function that seems to have been deprecated. sorry, unimplemented: non-trivial designated initializers not supported What is the correct way to implement the following data storage system in C++ for memory constraint systems? typedef union union_t { float f; int i; } arg; typedef struct type_t { int a; arg b; int d; } element; const element list[] = { { .a = 1, .b = { .f = 3.141519f }, .d = 6 }, { .a = 3, .b = { .i = 1 }, } }; Often the use of std

SWIG how to access a byte array from a c struct in Lua using a Lua table to manipulate

我是研究僧i 提交于 2020-01-25 02:52:29
问题 I am trying to access a array in a c struct from Lua. I want to access it as byte array. I know I have to use typemaps somehow but I am not able to get it working like I want to. the struct is defined within a namespace if that matter at all. For this example I call the headerfile send.h namespace foo{ namespace bar{ typedef struct { ... unsigned char data[8]; } message; }}; So I want to be able to access the unsigned char data array from the c struct from Lua. I want to access it like a