Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
3 votes
2 answers
196 views

I am writing hardcoded calls of functions that takes array(s) in parameter, e.g. int foo(size_t length, const int array[/* length */]); In order to avoid the error-prone process of keeping track of ...
2 votes
1 answer
121 views

I would like to initialize a NULL terminated array of pointer to struct using compound literals. Currently, I achieve this by: struct object { int data1; char data2; }; struct object *...
5 votes
2 answers
110 views

Check following contrived code: #include <stdio.h> typedef struct { void *ctx; } A; int main(void) { A b; { A a = {&(int){3}}; printf("%p\n", a.ctx); ...
Nan Xiao's user avatar
  • 17.8k
4 votes
1 answer
87 views

Check following contrived code: #include <stdio.h> void print_int(int *p) { printf("%d\n", *p); } void print_double(double *p) { printf("%f\n", *p); } #define ...
Nan Xiao's user avatar
  • 17.8k
1 vote
2 answers
158 views

I was reading C Notes for Professionals, in which, it claims that Compound Literals can only be lvalues. But LLMs have mixed answers upon that stating it could depend upon the context and could be ...
1 vote
1 answer
87 views

I have the following types: typedef float vec4[4]; // from cglm typedef struct Node Node; struct Node { float expand; vec4 color; Node *children; } For some reason, the color field's ...
2 votes
1 answer
151 views

I have 3 integers A, B & C from which I make pointers that I group in an array arrayABC of pointers to pointers: int A = 1; int B = 2; int C = 3; int *ptA = &A; int *ptB = &B; int *ptC = &...
1 vote
2 answers
171 views

I tried to initialise a structure via a compound literal in a function. After solving a part of my problem (see Use of compound literal inside a function to init a variable in C), I have a new problem ...
1 vote
2 answers
114 views

This question follows this one : Is there a syntax in C to DIRECTLY INIT a struct member that is a const array of constant literal?. Eric Postpischil gave me a solution using compound literals. Now, I ...
2 votes
1 answer
102 views

I have two functions that return a struct, one returns it via compund litearal and the other initializes a variable to then return it: typedef struct { int storage[256]; } data_t; data_t ...
2 votes
2 answers
155 views

I'm trying to declare some constant data structures in my code, ideally without having to declare subelements (this is a follow-on from a previous question about multiple lists of strings: different ...
1 vote
3 answers
289 views

I am trying to figure out if it's possible to do the following, but without having to declare the individual variables... static char *set_list1[] = { "set", "one", NULL }; static ...
0 votes
1 answer
80 views

I stumbled on the following stuff in someone's source code in C: typedef struct { u32 reg; } reg_t; #define _REG(r) ((const reg_t){.reg=(r)}) #define REG_A _REG(123) #define REG_B _REG(456) ... ...
2 votes
2 answers
153 views

I've found compound literals a very useful and elegant way to send initialized arrays and structs to functions without writing overly verbose code, but I want to understand the cost of writing code ...
1 vote
1 answer
264 views

The following code: struct Int { int i; }; const struct Int i = {sizeof(int) ? (int){1} : 0}; Results in: initializer element is not constant (Live demo GCC) Even though those statements are at ...

15 30 50 per page
1
2 3 4 5
...
10

AltStyle によって変換されたページ (->オリジナル) /