struct

Returning struct from c++ dll to Python

余生颓废 提交于 2020-01-05 07:06:11
问题 I'm trying to return structure so I can use it in Python. I am beginner programmer so please explain me what am I doing wrong. I've succeeded to return simple ctypes earlier (bool, unsigned int) but struct is too complicated for me. This is what I have: DLLAPI.h #define DLLAPI extern "C" __declspec(dllexport) ... DLLAPI myStruct* DLLApiGetStruct(); DLLAPI.cpp EDIT1: instead of TString, struct members type is wchar_t* now, but error I get is the same ... typedef struct myStruct{ wchar_t* id;

Is using the type `[my_struct]` the correct way of passing an array of C structs to a Rust function?

社会主义新天地 提交于 2020-01-05 05:46:04
问题 C file: typedef struct point { int x; int y; } point; typedef struct points { int count; point *array_of_points; } points; Rust file: #[derive(Debug)] #[repr(C)] pub struct point { x: c_int, y: c_int, } #[derive(Debug)] #[repr(C)] pub struct points { count: c_int, array_of_points: [point], } #[no_mangle] pub fn do_something(all_points: &points) { for i in 0..all_points.count { let crr_point = &all_points.array_of_points[i as usize]; println!("{:?}", crr_point); } } In my C file, I allocate a

Need help sorting an array of structures in C using qsort

天涯浪子 提交于 2020-01-05 05:45:08
问题 I have this struct. struct Transport { int id; float Price; }; Here I read the data into and array of structs. void read (struct Transport **Car, int *m) { int i; printf("Insert total number of cars: "); scanf("%d",m); *Car=(struct Transport*) malloc ((*m)*3*sizeof(struct Transport)); for(i=1; i<=*m; i++) { (*Car)[i].id=i; printf("Price: "); scanf("%f",&(*Car)[i].Price); printf("\n"); } } And here is the display function. void display(struct Transport *Car,int m) { int i; for(i=1; i<=m; i++)

C array of structure (exception thrown)

我只是一个虾纸丫 提交于 2020-01-05 05:39:05
问题 I have created an array of structure Human which consists of char *name . I use function like this: Human *createHuman(char *name){ Human *h = malloc(sizeof(Human)); h->name = strdup(name); return h; } I have tested this function, it works perfectly, but my problem starts when i use it like this: void gen_Humans(Human array[MAX], int n){ //n == max; for (int i = 0; i<n; i++){ char *name = gen_name_function_used_before_WORKING(); array[i] = *createHuman(*name); } … } As I said, if I generate

Blank initialising an array of structs in C99

六月ゝ 毕业季﹏ 提交于 2020-01-05 05:34:05
问题 This seems like a hole in my knowledge. As far as I am aware, in C99 if you initialise a single element of a struct and no others, the others are zero initialised. Does the following code zero initialise all the members of a struct though? typedef struct { int foo; int bar; char* foos; double dar; } some_struct_t; some_struct_t mystructs[100] = {}; Update: There are some comments indicating that this syntax is an extension. If that is the case, is there any way of doing this that is pure C99

openACC passing a list of struct

杀马特。学长 韩版系。学妹 提交于 2020-01-05 04:27:09
问题 I have a C program to find whether 2 sets of polygons are overlapped. User input 2 sets of polygon (each set of data has several thousands polygons) and the program see which polygon in set1 overlap with which polygon in set2 I have 2 struct like these: struct gpc_vertex /* Polygon vertex */ { double x; double y; }; struct gpc_vertex_list /* Polygon contour */ { int pid; // polygon id int num_vertices; double *mbr; // minimum bounding rectangle of the polygon, so always 4 elements }; I have

How to use decodable protocol with custom type values in Swift?

本秂侑毒 提交于 2020-01-05 04:18:50
问题 I have 2 types of response depending on my reuest: First one: { "status": "success" "data": { "user_id": 2, "user_name": "John" } } And second one is: { "status": "error", "data": [], } I am using struct like that: struct ValyutaListData:Decodable { let status: String? let data: [String]? } But if response is first type response, then an error occured. Because In first Type response data is not array. It is Json object. Then i use structure like that: struct ValyutaListData:Decodable { let

c, passing struct as argument

风流意气都作罢 提交于 2020-01-05 02:55:18
问题 I need to pass some structure as function argument like this void myFunc(unsigned char c); I will use myFunc(4) , myFunc(8) or so. Now the function accepts a structure as argument, so I tried typedef struct { unsigned char address; unsigned char command; unsigned char group; unsigned char response; unsigned char flags1; unsigned char flags2; }test_t; void myFunc(test_t test); myFucn({0,0,0,0,0}); // but this gives me error How can I pass const struct as argument without to have to instantiate

Structure not in memory

末鹿安然 提交于 2020-01-05 02:52:15
问题 I created a structure like that: struct Options { double bindableKeys = 567; double graphicLocation = 150; double textures = 300; }; Options options; Right after this declaration, in another process, I open the process which contains the structure and search for a byte array with the struct's doubles but nothing gets found. To obtain a result, I need to add something like std::cout << options.bindableKeys; after the declaration. Then I get a result from my pattern search. Why is this behaving

freeing substring in c - loop

旧城冷巷雨未停 提交于 2020-01-05 02:11:11
问题 I'm trying to get a sub-string for each member of the struct ' structs ' and then assign that sub-string to a new member of the temp_struct . The problem I'm having is how to free the sub-string on each iteration, for some reason the code runs, however valgrind throws an Invalid read of size 1 , which I assume I'm reading off the block of memory. How could I free the sub-string? Thanks #include <stdio.h> #include <stdlib.h> #include <string.h> struct st_ex { char product[16]; float price; };