struct

What can stay between “struct” and “{” except the structure name?

痞子三分冷 提交于 2019-12-23 23:39:01
问题 A clear example of how data structures can be used in C++ is given [here].1 This is one of the examples given on the linked page: struct product { int weight; float price; } ; product apple; product banana, melon; However, I have a code that does not follow this template and I cannot understand it. What I have is given bellow: struct result : mppp::data::table < row<semantics::user, int>, row<semantics::exitdatum, spmm::date>, row<userid, int> > {}; I do not understand why instead of struct

OpenCL kernel arguments

半城伤御伤魂 提交于 2019-12-23 22:18:54
问题 I've just started fiddling around with OpenCL and I've come across a problem: I do not know how to pass complex data structures as arguments. I'm using LWJGL's OpenCL binding, and the example provided in the wiki http://lwjgl.org/wiki/index.php?title=Sum_Example. In that example 2 float buffers are created and passed as arguments (LWGJL provides methods in a class named BufferUtils for creating these buffers). Now, how would I create a buffer of points, typedef struct {int x, int y} tpoint ,

getaddrinfo addrinfo result in stack or heap

假如想象 提交于 2019-12-23 21:52:11
问题 I am a bit confused at least. getaddrinfo() call 'updates' a pointer to a addrinfo struct, all is well when I am going to use the addrinfo in the same scope (that function) but what happens if I copy the struct to another one (by assigning it). Please help me understand the undergoing basics (not seeking advice for alternative approaches). Correct me if I am wrong: a) getaddrinfo() requires a pointer to struct-pointer to addrinfo. b) getaddrinfo creates a addrinfo struct in the current

Elegant way to convert a slice of one type to a slice of an equivalent type?

半城伤御伤魂 提交于 2019-12-23 21:42:39
问题 A motivating example: Implementing various scheduling "strategies", which sort a list of Jobs. type Job struct { weight int length int } // Given a slice of Jobs, re-order them. type Strategy func([]Job) []Job func Schedule(jobs []Job, strat Strategy) []Job { return strat(jobs) } One very simple strategy is to execute the shortest jobs first (disregarding their weight/priority). func MinCompletionTimes(job []Job) []Job { // Hmm... } Well, this strategy is nothing more than a sort on job

C++ initializer lists with fewer elements than the struct

有些话、适合烂在心里 提交于 2019-12-23 21:36:11
问题 When I use an initializer list to create a struct, but the initializer list contains fewer elements than my struct, I see the remaining elements are initialized with zeroes. Is this an undefined behaviour and I'm seeing zeroes because my compiler (VS2015) decided to zero the memory for me? Or could someone point me to the documentation that explains this behaviour in C++? This is my code: struct Thing { int value; int* ptr; }; void main() { Thing thing { 5 }; std::cout << thing.value << " " <

error: expression is not assignable ternary operator

谁都会走 提交于 2019-12-23 21:12:04
问题 I have the following code and MPLABX XC8 compiler gives this error: error: expression is not assignable U1ERRIRbits.RXFOIF ? uart1.oerr = 1 : uart1.oerr = 0; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ Here is the relevant code section: typedef union { struct { bool ferr : 1; // FERIF Framing Error bool aerr : 1; // ABDOVF Error bool oerr : 1; // RXFOIF Error bool ready : 1; // Data Ready to be read uint8_t reserved : 4; }; uint8_t status; }uart1_status_t; static volatile uart1_status

Sharing an array of structs using mmap

拟墨画扇 提交于 2019-12-23 20:11:43
问题 I am trying to create an array of structs that is shared between a parent and child processes. I am getting a segmentation fault when trying to access the array data. I feel certain that the problem has something to do with the way I'm using pointers, as this is an area I'm not very comfortable with. Please note that I edited out most of the code that didn't seem relevant. /* structure of Registration Table */ struct registrationTable{ int port; char name[MAXNAME]; int req_no; }; main() { /*

If only using the first element, do I have to allocate mem for the whole struct?

核能气质少年 提交于 2019-12-23 19:57:14
问题 I have a structure where the first element is tested and dependent on its value the rest of the structure will or will not be read. In the cases where the first element's value dictates that the rest of the structure will not be read, do I have to allocate enough memory for the entire structure or just the first element? struct element { int x; int y; }; int foo(struct element* e) { if(e->x > 3) return e->y; return e->x; } in main: int i = 0; int z = foo((struct element*)&i); I assume that if

Sharing an array of structs using mmap

橙三吉。 提交于 2019-12-23 19:51:50
问题 I am trying to create an array of structs that is shared between a parent and child processes. I am getting a segmentation fault when trying to access the array data. I feel certain that the problem has something to do with the way I'm using pointers, as this is an area I'm not very comfortable with. Please note that I edited out most of the code that didn't seem relevant. /* structure of Registration Table */ struct registrationTable{ int port; char name[MAXNAME]; int req_no; }; main() { /*

Why do I get this error creating & returning a new struct?

浪子不回头ぞ 提交于 2019-12-23 19:40:32
问题 I get an error when I compile this code: using System; public struct Vector2 { public event EventHandler trigger; public float X; public float Y; public Vector2 func() { Vector2 vector; vector.X = 1; vector.Y = 2; return vector; // error CS0165: Use of unassigned local variable 'vector' } } hi! The compiler says: "Use of unassigned local variable 'vector'" and points to the return value. It looks to me that Vector2 become a reference type (without the event member it acts normally). What is