Questions tagged [struct]

1

votes
1

answer
59

Views

Copy const struct in flash to “normal” struct in RAM

Here is what I have, and there is still a problem - the compiler doesn't recognize the 'my_reg' structure type. ../Source/functions.c:609:16: error: 'my_reg' undeclared (first use in this function) ModBusIDReg = (my_reg)const_ModBusIDReg; // define structure in flash with constants struct { const un...
Gregory Helton
1

votes
1

answer
50

Views

C - Can I use the same functions for these two different lists?

A uni project I have involves sorting a very large set of data into two different lists, one which has a bunch of data on a city or country, and another which has that same data (on a city, this time), but also with some coordinates, like so: //used for cities and countries in the textual mode typed...
1

votes
0

answer
50

Views

How to avoid copying of a struct when it is a field in another readonly ref struct

I have a bunch of extension methods on Check defined below. These may be chained together, and some of them may create new instances of Check (because it is immutable itself, but the _Success flag (and other flags not shown below) might need to be changed). public readonly ref struct Check { public...
Fit Dev
1

votes
1

answer
29

Views

Mimic struct.field using reflect

How can I get the same value as reflect.TypeOf(struct.field) when using FieldByName when the field is an interface type? As seen here, if a struct field is an interface, reflect.TypeOf(struct.field) gives me the concrete type, but reflect.ValueOf(struct).FieldByName('field').Type() gives me the inte...
Soumya
1

votes
1

answer
51

Views

Padding a struct out to a precise size

Consider the following struct definition: #define SIZE ... // it's a positive multiple of sizeof(Foo*) struct Foo { Foo* ptr; char padding[SIZE - sizeof(Foo*)]; }; Given that SIZE is a positive multiple of the pointer size (sizeof(Foo*)), is it guaranteed by the standard that sizeof(Foo) == SIZE? I...
BeeOnRope
1

votes
1

answer
54

Views

Unknown length and multiple requirements for input

I'm working with a struct called objective, that consists of a char name with a max of 8000 characters (most of the time will be much smaller), an int id, an int duration and an array of ints called deps that can have between 0 and 9000 elements. Here it is: typedef struct { unsigned long id, durati...
MuchoG
1

votes
0

answer
72

Views

free() function in c on a struct generates a breakpoint without any error code

I'm trying to create a linked list of users in a social network in c. I have 2 modules: User - a struct which contains a username (char), number of friends(int) and a linked list of friends (each block in the list contains a name and a pointer to next friend of the User).the User module has methods...
Zuser
1

votes
0

answer
37

Views

How to Pass Around Structs Containing Either Pointer Arrays or Static Arrays

I am passing around structs containing openGL vertex buffers and data to convencience functions that bind and update dateon the GPU. Right now, I have the following: struct VertexBufferData { VertexBuffer vbo; ElementBuffer ebo; size_t v_cap; size_t v_count; size_t i_cap; size_t i_count;...
synchronizer
1

votes
1

answer
12

Views

Assigning array of struct fails

This simple code crashes (Segmentation fault) and I don't understand why. Seems like this [] operation does not work properly with an array of structures. Maybe somebody knows the reason behind this weird behavior. #include #include #include #define SIZE 3 typedef struct{ int a; char * b; }qwe;...
DMykhail
1

votes
0

answer
59

Views

C incompatible Types struct return

The following code gives me a Compile error 'incompatible types at assignment' File 1: struct a{ int b; } File 2: static struct a c; void test(){ c.b = 0; } struct a getStruct(){ test(); return c; } File 3: static struct a d; void setStruct(){ d = getStruct(); (
serc
1

votes
1

answer
166

Views

Python tuple data byte to string easy way?

I'm using socket, struct for receive and unpack the received bytes message via tcp/ip protocol, I'm getting tuple which contains numeric data as well as bytes in the defined order as per contract. The example data as below... Example: receive buffer data from tcp ip buffer = sock.recv(61) Unpack the...
1

votes
1

answer
48

Views

qsort on dynamic array of dynamic structs [duplicate]

This question already has an answer here: How to qsort an array of pointers that use structs? 2 answers I have the following struct struct FOO { int x; double y; } and the array FOO **manyfoos; manyfoos = malloc( 10 * sizeof(FOO *) ); After this manyfoos is filled with dynamically allocated FOO * e...
Yese1967
1

votes
1

answer
404

Views

How to get latitude and longitude from google map api using go language?

How to get 'lat' and 'lng' from location in geometry using go language ? I'm trying to get latitude and longitude to use it for next api to fetch weather of specific location. I am getting an error when running the code: panic: runtime error: index out of range My response looks like this: https://...
1

votes
2

answer
156

Views

Explicit struct layout with Guid

I'm trying to have an explicit struct layout where I am reinterpreting a byte array as guids. This works fine when running in 32 bit for both .net 4.7 and .net 4.7.2. But when you run it in 64 bit it works in .NET 4.7, but doesn't seem to work in .NET 4.7.2. Is this code invalid or could this be...
Todd Hansen
1

votes
0

answer
184

Views

How create new field inside the struct using MATLAB?

I have 1 struct (the name of the struct is 'patient_1') consist of 1 cell (the name the cell is 'A1') inside the cell A1, there are 36x1 values which all of them are the struct. inside the patient_1.A1, there 2 fields, such as the screenshot below My question is how to create new field inside the s...
Agnes Palit
1

votes
0

answer
403

Views

Import file CSV to struct using MATLAB

I am trying to input file CSV and convert it as struct in matlab. This is the sample 'file_1.csv': and 'file_6.csv': If you take a look at those files, both of them has similar structure, even the content data are different. To convert the CSV files to struct I am using matlab by using this code: fi...
Agnes Palit
1

votes
1

answer
41

Views

How to fix indexPath error in viewDIdLoad?

I have problem with indexPath.row. Inside the cellForRowAt this lines work perfect: let cell = tableView.dequeueReusableCell(withIdentifier: 'MenuViewCell', for: indexPath) as! MenuViewCell let item = converters[indexPath.row] cell.ConverterName.text = item.converterName cell.converterImage.image =...
Ivan Kisin
1

votes
0

answer
87

Views

Is a struct to perform cleanup at the end of scope a good C# pattern?

RAII is nice for ensuring you don't fail to call cleanup. Normally, I'd implement with a class. I'm currently using Unity and am conscious of generating garbage in Update (even in editor scripting). I was thinking, is creating a struct wrapper for Begin/End actions a good pattern for avoiding alloca...
idbrii
1

votes
2

answer
191

Views

How can i append JSON with multiple struct into array?

In order to parse the JSON, I needed to use 3 structs. struct AppleApi: Decodable { let feed: Feed } struct Feed: Decodable { let results: [Result] } struct Result: Decodable { let artistName: String let artWorkUrl: String enum CodingKeys : String, CodingKey { case artistName = 'artistName' case art...
1

votes
1

answer
25

Views

2D array of structs in heap memory C

I keep getting a segfault when I try to initialize a 2D array of structs in dynamic memory. I know a 1D array of structs is technically a pointer to a pointer, I figured a 2D array of structs also functioned that way, but it seems like maybe not? Code: typedef struct PTE { unsigned int faddr:7;...
Thomas M
1

votes
0

answer
36

Views

An error of hive handles column of timestamp in struct?

I am in GMT +0800. When I use hive to process column of timestamp, if this column is in a struct type column, there will be the following. hive> desc ts; t timestamp s struct hive> select * from ts;...
xuejianbest
1

votes
0

answer
70

Views

Swift nested enums/structs to string in reverse order

When using string keys in UserDefaults or any other service, it is a common practice to '.'-separated words to build my keys. For example: 'com.domain.subdomain.scope.key' Sometimes, we have multiples key names for a same scope or multiple scopes for a same subdomain (or whatever wording we want to...
vilanovi
1

votes
0

answer
144

Views

oracleConnection.createARRAY not working with WebLogic Data Source Connection

So, I was using a datasource which was defined in Spring, which was working fine. Then I updated my project to take the datasource from the Weblogic server which the application is running on. This too, works fine for most calls to the database, except for one scenario - This scenario is involved se...
semiColon
1

votes
0

answer
38

Views

Struct unpack MemoryError

I'm triyng to read a image binary file into RAM with struct unpack. Binary file has 120MB and every pixel is represented by 16 bits. For presition purposes later in computation, I need to cast 16 bit data into float64 numpy array... According to my computation, I need in RAM 524MB to read all data....
eduardosufan
1

votes
0

answer
19

Views

Can you document the memberwise initializer for a Swift struct, without redefining it manually?

Say I have a struct in Swift: struct MyStruct { let myInt: Int let myString: String } I get a memberwise initializer for this struct by default MyStruct(myInt: Int, myString: String) But, even if I document this struct and its properties, I won't get any documentation for this memberwise initializer...
tnev
1

votes
0

answer
67

Views

supporting a new format character in python's struct.pack_into

I have a python struct format string that I'd like to split up over multiple calls to struct.pack_into, like so: buff = bytearray() fmt = '!BBi4sVi3s' args = [1, 0, 4, 'abcd', 6, 3, 'abc'] offset = 0 fmt_parts = fmt.split('V') for fmt_part in fmt_parts: struct.pack_into(fmt_part, buff, offset, *args...
Emmett Butler
1

votes
0

answer
42

Views

GCC end-aligned structure

I am working on a memory allocator. Each allocated buffer starts on an 8-byte boundary and each is preceded by a header for managing the allocation (the header is immediately before the 8-byte-aligned buffer). The header looks like: struct header { uint32_t hword32; void *hpointer; }; Ass...
1

votes
1

answer
40

Views

Only the first added item to struct is uploaded to firebase

I want to upload all info in my Struct to Firebase, but I´m only getting the first item added to upload. I'm also displaying the Struct in a tableView and this works great. Struct File: struct Products { var name: String = '' var amount = Int() } var prodItems : [Products] = [] The struct...
Anvil
1

votes
0

answer
15

Views

how can i pass a struct inside a linked list?

I'm new to c language, I always find this site very helpful but could not find a clear answer to this problem. im having a hard time to send a struct with 3 fileds as a linked list value. this is the function: void add_to_list(list *s, find_indexs * q) { list_node* ln = (list_node*)malloc(sizeof(li...
netanel94
1

votes
0

answer
43

Views

Cannot print out []byte data MQTT

I have a function that takes in JSON data sent using MQTT and unmarshalls it into a struct. I then marshal the struct into a JSON for the purpose of checking whether it holds the desired values. My issue is that I am unable to print out the data after I marshalled it. Here is my code: func Virtua...
Ruby
1

votes
1

answer
31

Views

c++ convert a function argument (Struct with template variables) to a string inside a function body

I have a template class defined below. I pass the struct to a function like this: Function call function({2, 2}) Function declaration void function(UnsignedVector2D pad) { //get `pad` as a string so that I can write it to file } My question is - I want to keep a record on the vales of pad that are...
ariane cathal
1

votes
1

answer
101

Views

Trying to access first member(itself a volatile pointer) of struct pointer does not return the stored member pointer but the struct address

I am trying to implement some pointer substitution for some communication interface by passing on a pointer to a struct of pointers to some implementation. This is meant to run on an Atmega328p and is being compiled with avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 4.9.2, installed in/via msys2...
Saphieron
1

votes
1

answer
76

Views

How to pass a slice of structs to template and iterate them in Golang?

I want to pass a slice that contains structs and display the all the values in the view. type Person struct { ID int NAME string } Example of a slice of structs [{1 John},{2, Mary},{3, Steven},{4, Mike}] What I want in index.html 1 - John 2 - Mary 3 - Steven 4 - Mike
ShiningGo
1

votes
1

answer
79

Views

Parse yaml error for map

I've the following program in which I need to parse yaml with the following structure https://codebeautify.org/yaml-validator/cbabd352 this is valid yaml and I use byte to make it more simple maybe the indentation was changed during the copy paste to the question but you can see in the link that t...
1

votes
0

answer
62

Views

C++ pointer to own struct member has different value after reassignment

I'm using Visual Studio 2017 and came across a bug which I cannot understand. I have this code as an example: #include struct Foo { int a = 0; int c; int *b; Foo(int n) { a = n; b = &c; } }; struct Bar { Foo nestedFoo = Foo(0); Bar(int n) { std::cout
Guilherme Nemeth
1

votes
2

answer
50

Views

trouble trying to use a struct variable

I’m learning C programming and I’m trying to make a simple program to store points in the XY plane. At first I did it like this: #include #include typedef struct point { float x, y; } PNT; typedef struct plane { int n_points; PNT pt[50]; } plane; void points_input(plane planexy); void points_dis...
Ragde Nutzer
1

votes
1

answer
107

Views

rendering html templates golang revel

I am hoping someone will be able to help me out. I have started building a web app and decided to go with GO and Revel. So far I've learnt quite a few things but there is this one functionality I can't seem to be able to get working. I have the following code: package controllers import ( 'github.co...
1

votes
1

answer
131

Views

Convert C typedef struct to Swift [closed]

I have this C typedef struct: typedef struct _HEADER { BYTE HeaderTag[16]; UINT16 __unused_field_1; UINT16 __unused_field_2; UINT32 data; UINT64 size; UINT32 UpperHeaderSize; UINT32 LowerHeaderSize; U...
vikkuu
1

votes
0

answer
209

Views

Swift get struct properties from type reference

I'm trying to loop over the struct properties but I only have reference for struct type not fully initialized struct. if I were to have an initialized struct I can use the mirror methods but I only have a type reference from generics. Here in my code I'm trying to generate other code for some reaso...
Mehmet Emin Kartal
1

votes
0

answer
67

Views

Define python struct value as struct itself

I'm trying to create a resulting struct based on input struct. Code looks similar to this: from google.protobuf.struct_pb2 import Struct resulting_struct = Struct() for key, value in input_struct.items(): if value != '': resulting_struct[key] = value It works fine except of one moment: If the type...

View additional questions