Questions tagged [struct]

A keyword in various programming languages whose syntax is similar to or derived from C (C++, C#, Swift, Go, Rust, etc.). Use a specific programming language tag to tag questions involving use of a `struct` as syntax and semantics can be language dependent. Keyword defines or declares a data type composed of other data types. Each member of a struct has its own area of memory (as opposed to a `union` whose members share a single area of memory).

Filter by
Sorted by
Tagged with
0 votes
1 answer
14 views

Exploding a StructType column in PySpark

Is there a way to explode a Struct column in a Spark DataFrame like you would explode an Array column? Meaning to take each element of the Struct (a key-value pair) value and create a separate row for ...
Filip Megiesan's user avatar
-5 votes
1 answer
45 views

Why is my pointer value changing when I read from it? [closed]

I have two structs: typedef struct configInfo_s{ uint8_t txRx; uint8_t frameLen; etc... } configInfo_t; and typedef struct testData_s{ configInfo_t config; uint32_t buf[6]; ...
ahzired's user avatar
-1 votes
2 answers
55 views

Assigning values Struct to Struct in SwiftUI

I'm pretty new to SwiftUI. and I'm facing some kind of errors while I tried to do this.I have two SwiftUI File of struct like Struct A: MY { let id: int var name: string? } Struct B: One { let id: ...
VizVyz's user avatar
  • 65
-2 votes
0 answers
55 views

Interface and struct in golang [closed]

I was learning Go myself and I understand the basics of Structs & Interfaces. However, while delving more into this, I keep hearing the proverb "Accept interfaces, return structs” in Go. I ...
user8479984's user avatar
3 votes
2 answers
49 views

Overloading methods for parametrized struct

Short Version I have a struct like @kwdef mutable struct Params{B, C} a::Float64 = 42 end where B and C are symbols that will determine which function to use out of many functions that are ...
Jared Frazier's user avatar
0 votes
0 answers
25 views

Is it possible to suppress Binder Error: Could not find key in duckDB

When querying for a field that is not part of the struct in duckDB you get the following error. Is it possible to suppress this error and return NULL? Current behaviour: SELECT a.b FROM (SELECT {...
Owen's user avatar
  • 98
-2 votes
2 answers
75 views

What is the purpose of typedef of an enum in C Language?

I ran into the following code and I'm trying to understand how this code works and the reason it was used. enum eKeyEvent { eNoEvent = 0, eKeyChanged }; typedef enum eKeyEvent eKeyEvent_t; ...
Gromit's user avatar
  • 11
1 vote
1 answer
39 views

Python Struct giving unexpected result

If I use this code snippet in python I get an error single_participant_info = "3h3hHbbbbHBBffH" format_string = single_participant_info * 32 unpacked_data = struct.unpack(format_string, data)...
RangeyRover's user avatar
1 vote
1 answer
39 views

How to combine structs in go for network devices?

I am trying to implement a structure (in a kind of capturing program) for keeping network devices' list in golang. Each device-type both have some basic network attributes (which are applicable to all ...
E. Gündüz's user avatar
-1 votes
0 answers
22 views

Is it possible to convert Struct MVC back-end service to Spring-boot MVC backed micro service?

Currently I'm working on Struct MVC (Java 1.4) back-end service to construct page for front-end for reputed mobile application and web application which currently more than 100k users are using. ...
Malith Hirantha's user avatar
1 vote
3 answers
62 views

qsort in struct, but the sorted struct is messy

I want to sort an array of struct using qsort by their name, But the output is not what I expected. typedef struct node{ char name[64]; char ingredient[10][64]; }node; int compare(const void *...
ident's user avatar
  • 68
0 votes
1 answer
29 views

What to do when error 'Ordering by expressions of type STRUCT is not allowed' and ordering is in qualify row number over() statement?

I encountered a problem and since I'm not incredibly advanced in SQL, I fail to solve it. I wanted to use for ordering two conditions, first one dependent on the status, then dependent on the type. ...
xxx_anna's user avatar
-2 votes
0 answers
34 views

Go: Unmarshal flat JSON file to nested struct

I'm looking forward to best approach to Unmarshal the following JSON file { "server.port": 8080 "database.dsn": "postgres://postgres:[email protected]:5432/dummy", &...
Davi Diório Mendes's user avatar
0 votes
1 answer
70 views

How to initialize a compound literal with a value of the same type?

for example: typedef struct S { int i; char c; } S; #define MAKE_CLITERAL(T) ((typeof(T)) {T}) int main() { S s = {.i = 500, .c = 'a'}; S s2 = MAKE_CLITERAL(s); // doesn't compile } I want ...
Abdulmalek Almkainzi's user avatar
0 votes
2 answers
105 views

invalid conversion from void* to struct* in C++

I have a problem related with this implementation : struct arg_struct { int low; int high; }*args; void segmentedSieve(void * arguments) { arg_struct *args = arguments; /****do ...
DeadlyKitten999's user avatar
-4 votes
2 answers
52 views

Stuck on pset 3 (Runoff) HELPP

Can someone tell me why my code doesn't work. here's its description https://cs50.harvard.edu/x/2020/psets/3/runoff/. the error is most probably outside of the main function. edit - the issue has been ...
Hashim's user avatar
  • 3
0 votes
0 answers
39 views

How to partially parse JSON using Go partly without key?

I have this JSON { "version": 1, "sources": { "source1": { "type": "number", "url": "<path&...
Robbert's user avatar
  • 119
-1 votes
1 answer
31 views

Is is a good idea to wrap class instances in a struct? [closed]

I have a method that accepts a few arguments: public Something GetMeSomething(Class1 class1, Class2 class2, Class3 class3, bool someOption); I don't like the fact that it accepts so many arguments, ...
mnj's user avatar
  • 2,569
1 vote
1 answer
38 views

bubble sort in an structure in C

I've coded a program based on an array of structure and all parts of it are ok but one of my functions that is sort_student function has a bug. In this code at first the user will enter some students ...
Mani Aghaie's user avatar
-2 votes
0 answers
25 views

How to initialize? Problem: property initializers run before 'self' is available [duplicate]

I am trying to use the UUID of the „thing“ to initialize the „piece“. import SwiftUI struct ContentView: View { let thing1 = thingModel(titel: "nameOfThing1", col: Color.red) ...
plzHelp's user avatar
-2 votes
1 answer
84 views

removing a field from an array of struct

I'm working on a project and for that I need a function for removing a student by searching id but when I run it and enter a valid id to remove a student it doesn't work and it goes to else block and ...
Mani Aghaie's user avatar
1 vote
0 answers
74 views

Problem with returning large struct in Visual Studio 2013

This might seem obsolete, but I am working on a program that is supposed to work on Windows XP 32bit - we are still using a couple of those because of old EEG recorder that is incompatible with ...
Adam Kalina's user avatar
-1 votes
1 answer
49 views

Struct pointer not updating when passed to function [duplicate]

I have a header file and two source files. Below is the code in my tpool_pq.h file. typedef enum priority_t {LOW = 1, MEDIUM = 3, HIGH = 5} priority_t; typedef struct task_t { void (*function)(); ...
KRS Nandhan's user avatar
-1 votes
0 answers
30 views

Does defensive copying occur when structs refer to other structs?

For a personal project, I'm implementing two custom collections. The nature of these two classes is that there is an outer class with a reference to an inner class. These are classes that implement ...
tan x dx's user avatar
1 vote
1 answer
44 views

How to pass entire json string to a field of nested struct while unmarshaling?

I need to unmarshal flat json string data := `{"login":"Nickname","password":"some_pass","newPassword":"new_pass"}` into the ...
Andriy's user avatar
  • 1,282
2 votes
0 answers
76 views

Trying to pass a structure in c over a FIFO

I'm trying to pass a structure over a FIFO in c but cant seem to get the structure over to the client. Any help would be appreciated. created the structure and wrote it to the pipe. Not sure if i did ...
jjmoe43's user avatar
  • 29
2 votes
2 answers
74 views

Pointer to member of returned struct, is it safe?

for example: struct A { char s[10]; } f() { struct A ret; scanf("%9s", ret.s); return ret; } int main() { char *str = f().s; puts(str); } is str pointing to a ...
Abdulmalek Almkainzi's user avatar
0 votes
0 answers
30 views

Rust split Vec<u8> into a struct of arrays of certain lengths [duplicate]

So I have a bytecode file that is made up of 32 sectors of 4KiB of data that I wanted to store in a struct like this, I was able to get the u16 and u32 values to work. I'm only having trouble turning ...
That Human Being's user avatar
0 votes
1 answer
65 views

How can I get decoded data from a struct inside a struct from an API [closed]

I am trying to learn how to use AlamoFire and I want to get the values of structures inside this struct MyData. How to achieve this ? import Foundation import Alamofire struct MyData : Codable { ...
bumblebee's user avatar
1 vote
0 answers
50 views

Override Spanner tag of embedded field

Let's say I have the following types: type Inner struct { Field1 string `spanner:"field1"` Field2 string `spanner:"field2"` } type Outer struct { Inner Field2 ...
Masedko's user avatar
  • 11
2 votes
0 answers
35 views

C: for a smallish struct, returning struct or returning reference to struct? [closed]

In C; If a struct is small, because it mainly consists of pointers to potentially large arrays; would it be "better" for functions to return a pointer to the struct or to return the struct ...
Sasha's user avatar
  • 215
0 votes
1 answer
85 views

How to initialize this struct values correctly?

I am kinda struggling to initialize structures correctly unfortunately and I am fairly new to using these here. How can I correctly initialize this struct and pass it into the function shown in the ...
Jamie 's user avatar
  • 421
1 vote
2 answers
103 views

Access an old struct as CPP class

I have a question about C++ standard, I know a class is compatible with C if does not have any methods, but I'd need to have some getters (mainly not to forget various htoi and friends) This is an ...
DDS's user avatar
  • 2,367
2 votes
0 answers
34 views

LLVM vs GNU assembler, how to replace .struct in LLVM

With the GNU assembler (arm64 target), I use .struct directives to define local layouts, for instance the stack frame of a function: .struct 0 // stack frame layout. mul.call_frame: ...
Thierry Lelegard's user avatar
1 vote
2 answers
84 views

By-value and by-reference distinction between List<T> and Array for custom struct and built-in structs (like Int32)

I know there is a small but important distinction between using indexers with List and Array. Array returns the reference for the member, whereas List copies the member value. Where I can't wrap my ...
Mehmet Ali Duran's user avatar
1 vote
2 answers
72 views

Initialize all elements in array to same value within the struct

Foreword - I seem to have a solution, but I am not sure it is correct because I do not understand how compiler handles it. And yes, I performed research, which did not convince me in reliable and ...
Anonymous's user avatar
  • 573
0 votes
1 answer
54 views

Static allocation of c struct with variable length array

I want to use a struct to store a variable length array of bytes (a UART message) and some other information/flags along with it such as length, what the message does etc. I have a struct defined: ...
wstuchbury-pathtrack's user avatar
1 vote
0 answers
32 views

How do I locate the gimple I want and change it?

I'm trying to write a pass in gcc to implementing structure splitting. And I'm having a problem that I don't know how to locate the gimple that I want and I need to change it of course. This is the ...
Dbettkk's user avatar
  • 71
0 votes
1 answer
55 views

Object instance still accessible after destruction

I have an Animal struct that has Dog struct as a data member, my question is why the Dog instance that is created (inside the Animal) is still accessible through the allocated instance of Animal even ...
username's user avatar
0 votes
0 answers
23 views

How can I write an enumerator for nested unmanaged enumerables?

I've written enumerators based on the existing NativeHashMap.Enumerator and UnsafeHashMap.Enumerator structs that work in burst, but I am running into trouble when I try to combine enumerators for ...
Disciple153's user avatar
1 vote
0 answers
49 views

How to implement strcuture peeling through creating a pass in gcc?

I'm tring to write a pass to implement structure peeling in gcc to make it faster. Structure peeling is a way to make cache happy through spliting the origin structures into hot fields and cold fileds....
Dbettkk's user avatar
  • 71
0 votes
2 answers
109 views

Dynamic memory allocation and pointers

I'm struggling with pointers and their allocation. I'd like to understand if I'm allocating correctly and how it should be done otherwise. Also, I get warnings regarding the fgets and puts function ...
DM10's user avatar
  • 3
2 votes
1 answer
46 views

flexible array size within typedef for const struct member

I would like to use C-code for a struct type having a member of type pointer to a flexible sized array. But the access to the array elements fails when the array-size is not specified in the type ...
hypnoticum's user avatar
0 votes
1 answer
19 views

MethodError in Inner Constructor with Vector Input

I'm trying to implement a SparsePolynomial type that stores the terms as items in a linked list (from DataStructures.jl) with a dictionary pointing to items in the linked list. This struct takes input ...
mysterymachine's user avatar
0 votes
0 answers
25 views

Dart FFI Struct From C

typedef struct _TEST_NAME { // variables union { UCHAR FlagGroup[4]; ULONG Flags; struct { ULONG PackagedBinary : 1; ULONG ...
Kirill's user avatar
  • 1,189
0 votes
4 answers
122 views

Can I assign or return a struct with unassigned elements in C?

In C, using an uninitialized variable is undefined behavior. Including: int x; int y = x; However, suppose I have the following: struct Struct { int a; int b; }; struct Struct s; s.a = 1; ...
user16217248's user avatar
  • 3,230
6 votes
2 answers
268 views

How to turn only member variables into byte array in C++?

TL;DR I have a struct with more than just member variables (e.g. they contain functions), and I want to convert only the member variables into a byte array(/vector), such that I can upload data to the ...
Tare's user avatar
  • 542
-1 votes
1 answer
51 views

How to associate data with struct without increasing size in C++

In a renderer, I have a MaterialParameters struct as a base class(/base struct). For every shader in use, a user would need to create ther own struct inheriting MaterialParameters with all the info ...
Tare's user avatar
  • 542
1 vote
1 answer
22 views

Julia - constructor error when a field is a Vector of Functions

I created a mutable struct with a field of type Vector{Function}. When I use a constructor with only this field as an argument, I get a MethodError. Here is minimalist example with a constructor with ...
Xavier Lebeuf's user avatar
0 votes
1 answer
14 views

remove typedef from struct function pointer

The code below works as advertised. However, I don't quite understand the mechanism of "typdef" in this application (I understand its use for the struct) so I would like to remove them to ...
jwzumwalt's user avatar
  • 203

1
2 3 4 5
606