Linked Questions
17 questions linked to/from Unsized array declaration in a struct
5
votes
2
answers
7k
views
Unsized array declaration inside struct ok? [duplicate]
Is the following supposed to be valid for the declaration of table_type, specifically the e[]:
struct table_type
{
unsigned int8 a;
unsigned int8 b;
unsigned int8 c;
unsigned int8 d;
...
1
vote
0
answers
40
views
Class with incomplete char array [duplicate]
In a library for binary messaging, I have some structs like these:
struct __attribute__((__packed__)) Header {
int16_t msg_type;
int16_t msg_size;
char payload[];
};
struct __attribute__(...
44
votes
4
answers
3k
views
Internal mechanism of sizeof in C?
I use sizeof to get size of a struct in C, but the result I got is unexpected.
struct sdshdr {
int len;
int free;
char buf[];
};
int main(){
printf("struct len:%d\n",(sizeof(struct ...
17
votes
2
answers
3k
views
Are flexible array members really necessary?
A struct with a flexible array member, apparently, is not intended to be declared, but rather used in conjunction with a pointer to that struct. When declaring a flexible array member, there must be ...
14
votes
1
answer
2k
views
What is the use of 0-length array (or std::array)?
In C++11 it allows you to create a 0 length C array and std:array like this:
int arr1[0];
std::array arr2<int,0>;
So I'm thinking what is the use of a array that doesn't have a space to store?
...
3
votes
2
answers
1k
views
variable length structures in C90
Zero-length arrays are allowed in GNU C.
and can be initialized thus
struct line {
int length;
char contents[0];
};
struct line *thisline = (struct line *)
malloc (...
0
votes
2
answers
2k
views
Pass struct pointer element to FIFO - C
I am developing a client/server application in C, in which multiple clients send requests through a common FIFO.
The data being sent to the server is a struct containing multiple parameters ...
4
votes
2
answers
1k
views
shared_ptr to variable length struct
How can I combine the variable length struct idiom
struct Data
{
std::size_t size;
char data[];
};
with the make_shared idiom which does essentially the same thing so that I can end up with a ...
1
vote
2
answers
2k
views
Undeclared Variable in struct C
My struct code is just like this:
typedef struct
{
int w;
int h;
float m[w][h];
} Matrix;
But I'm just getting this errors:
"error: 'w' undeclared here (not in a function)"
"...
0
votes
2
answers
2k
views
Declare Global Struct Variable With Variable Size In C
I have a struct that looks like this.
struct MyStruct1 {
int (*fn)();
int b;
}
And another struct that looks like this.
struct MyStruct2 {
int a;
struct MyStruct1 b[0];
}
I would ...
0
votes
3
answers
764
views
Why am I getting this error-:expected primary-expression before 'bool'?
#include<iostream>
#include<string>
using namespace std;
class LFSR
{
private:
bool lfsr[];
private: int tap;
private: int t;
private: string s;
public:
LFSR(string ...
0
votes
1
answer
968
views
Issue with devm_kzalloc
I am trying to understanding devm_kzalloc() function implementation. It is allocating more than the requested memory(sizeof(struct devres) + size) to manage resources.
struct devres is defined as ...
2
votes
3
answers
200
views
Variable-length strings in structures and undefined behavior causing time travel
In this Stackoverflow question or in the article Undefined behavior can result in time travel (among other things, but time travel is the funkiest) one may learn that accessing data structures at ...
-1
votes
3
answers
208
views
Finding the size of the structure dynamically
Is there any way to find the structure size dynamically in C??
Sizeof is compile time operator.. so what's the other option.
If we can have dynamically allocated array(flexible arrays) in a ...
3
votes
1
answer
150
views
Is it safe to use an out-of-bound index with an smaller array, which is casted from a large enough array?
In my day job, I have encountered a lot of C codes resembling the following pattern. I am worrying whether this pattern is safe.
typedef struct
{
unsigned char someField : 4;
unsigned char ...