Linked Questions
83 questions linked to/from How to initialize a struct in accordance with C programming language standards
41
votes
6
answers
268k
views
Initializing array of structures [duplicate]
Here's initialization I just found in somebody else's question.
my_data data[]={
{ .name = "Peter" },
{ .name = "James" },
{ .name = "John" },
{ .name = &...
13
votes
3
answers
1k
views
C structure initialization? [duplicate]
How can I initialize a structure if one field in the structure is itself a structure?
6
votes
2
answers
3k
views
Partial initialization of struct? [duplicate]
Is it possible to statically initialise part of a struct?
The stuct I have:
struct data {
char name[20];
float a;
int b;
char c;
};
When initialsing and printing:
struct data ...
2
votes
3
answers
6k
views
Initializing function pointers in struct [duplicate]
typedef struct foo{
void (*del)(void *toDel);
char* (*p)(void *tp)
} Foo;
Foo init(char* (*print)(void*),void (*delFunc)(void*));
Trying to figure out how to assign or initialize the supplied ...
0
votes
1
answer
2k
views
Set initial values to fields of a struct in c ? [duplicate]
Possible Duplicate:
How to initialize a struct in ANSI C
I have a global variables in my code with initial values , which are :
int init = 0;
int flag = FALSE;
sem_t *mutex;
char * ptr1 = NULL;
...
0
votes
2
answers
744
views
How to initialize a structure on definition? [duplicate]
Is there a way to declare a structure with default initalisation values?
I have a header file which defines a structur like this:
typedef struct struc_s
{
size_t cost const = 2000;
size_t ...
-1
votes
3
answers
465
views
Array of function pointers as a member of a C struct [duplicate]
I have built the following C example trying to simulate simplistic generic driver code which can be used in small ARM micro-controllers:
#include <stdio.h>
#include <string.h>
typedef ...
1
vote
1
answer
188
views
initialize member of sub-sub struct [duplicate]
I wonder if there is a way to initialize a member of a member of a struct. Let`s say I have 2 structs, t1 and t2. t2 contains 2 instances of t1. like this:
typedef struct t1{
int ...
-1
votes
2
answers
183
views
Syntax error when adding a bool field to a struct (expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token) [duplicate]
typedef struct {
char fielda[ 2 ][ FIELD_A_MAX + 1 ];
bool fieldb = false;
bool fieldc = false;
sem_t fieldd;
} Set;
I get the error:
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ ...
1
vote
0
answers
207
views
Identifier "character" is undefined [duplicate]
I am getting the error identifier "character" is undefined. I have included the header file as well and still cannot figure out the reason behind it. The screen shot of the error
The print....
-1
votes
2
answers
134
views
Error expected expression before '{' token [duplicate]
typedef struct{
int num, den;
} tfrac;
tfrac multf(tfrac a, tfrac b);
tfrac multf(tfrac a, tfrac b){
tfrac res;
res={a.num*b.num, a.den*b.den}; //The ERROR is here
return res;
}
This program ...
0
votes
1
answer
132
views
Initialise const struct and be clear which field is which [duplicate]
I want to initialise a const struct:
const struct MyStruct MYSTRUCT_DEFAULTS = {
"prop1",
"prop2",
"prop3",
123,
456,
...
}
However in the above it is impossible to tell which field is ...
1
vote
1
answer
104
views
Structure variable initialization in short way [duplicate]
Trying to initialize structure variable fields with values in short way:
typedef struct
{
int id = 0;
char* name = "none";
}employee;
employee e =
{
.id = 0 ;
.name = "...
0
votes
0
answers
43
views
Constuct name for assigning C functions like .pr_input = sctp_input [duplicate]
Can someone tell me the name for assigning functions like this in C -
.pr_type = SOCK_SEQPACKET,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags =...