30,775 questions
1
vote
0
answers
64
views
how i can populate struct type only in returning joined column from sql
I have a table named tasks where have relationship one-many to another table (projects), i want to query tasks with projects but only return selected column from the projects table. how i can do that ...
11
votes
1
answer
664
views
Is CPP TrivialCopyable class effectively a C struct?
During coding of std::atomic, CAS, etc, I always struggle to memorize the definition of CPP class being "TriviallyCopyable".
Now I am gradually switching to C world, I accidentally found ...
3
votes
1
answer
109
views
Pass C struct as "deep" const
I have a struct which holds some pointers to data it does not own, e.g.:
struct s {
int* x;
int* y;
};
I can then pass it as a const pointer itself:
int foo(const struct s* s) {
return *s-...
6
votes
2
answers
200
views
How do I calculate the end address of a C struct in memory?
I have the following structure in my .c file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Student {
char* name;
int age;
int id;
} Student;
...
0
votes
2
answers
141
views
I'm writing a parser in C++ for my programming language, but I don't figure out how to represent token trees [closed]
I want to create a parser in C++ for my programming language. Its logic is a little different than usual, because I want to first organize tokens in blocks (such as expressions or IDs, that are ...
1
vote
1
answer
82
views
Is [[__no_unique_address__]] applied to second members in this tail padding optimization check in libc++ redundant?
In the libc++ implementation of std::expected, there is this helper variable template:
// This function returns whether the type `_Second` can be stuffed into the tail padding
// of the `_First` type ...
1
vote
2
answers
138
views
Simulating (as far as possible) anonymous struct declaration + dynamic initialization
In some languages, we can declare and initialize an anonymous struct - or the equivalent thereof - seamlessly. Example from ECMAScript:
function foo_in_ecmascript(x) {
let computed = {
...
4
votes
1
answer
97
views
C struct assignment by unnamed struct initialized by member-wise list, syntax candy or unintentional memory overhead?
Prior statement: I'm a programmer long coding in C++ and Python, so kindly pardon and teach if my question looks too silly due to my thinking of C in an OOD way. Also I've tried lot searching on ...
14
votes
1
answer
855
views
What is correct mental model for [[no_unique_address]] in C++?
I recently found out about [[no_unique_address]] attribute in C++. According to cppreference.com:
Applies to the name being declared in the declaration of a non-static data member that is not a bit-...
2
votes
1
answer
168
views
Declareing array that stores a struct, which defined in another file included, gives the error "Incomplete Type "Array[]" is not allowed"
I have defined a struct in another file called file1.h (example) and when I declare an array using that struct in another file called File2.h, i get the error Message:
"Incomplete Type "...
0
votes
0
answers
32
views
tradingview! Persistent Pine Script v6 error: Syntax error at input 'end of line without line continuation'
It affects any struct. I've cleaned chars, renamed, tried new scripts – still fails.
Any solutions? So frustrating.
//@version=6
indicator("TestStruct", overlay=true)
struct MyData
float ...
1
vote
1
answer
120
views
How to efficiently parse data packets into structs
I am currently building functions that take packets of CAN bus data and parse them into structs depending on their ID as seen below.
Is there a more 'cleaner' way of parsing data into structs instead ...
4
votes
1
answer
111
views
(C) Accessing Arrays with Indices and Components
I'm writing a library for matrix and vector mathematics and I find it would be convenient to access vector components as if the vertex were both an array vector[2] and a struct vector.y, all while ...
0
votes
2
answers
122
views
Can't call struct function outputs in main function in C
I have a struct function which scans in coordinates, but when I call the function in my main function it doesn't seem to carry over any of the values and I get an error for 'use of undeclared ...
2
votes
1
answer
152
views
Does allocating a buffer smaller than the size of a struct cause undefined behavior, even if I do not reference any would-be out-of-bounds members?
Suppose I have the following:
struct S {
char b[256];
};
struct S *buf = malloc(128);
buf->b[0] = 1;
You may notice that the allocation size is smaller than the structure size, but at no ...