default values for C struct fields

Newbie Member
15Jan2008,13:11   #1
drichird's Avatar
of course can't do this

typedef struct {
char name[50] = "not_set_yet";
int ssn = 111223333;
} employee;

is: employee emp1 = {"not_set_yet", 111223333}; the only way?

what is the most elegant way to have default values for all instances of that type of struct?
Ambitious contributor
15Jan2008,15:23   #2
Salem's Avatar
You write it as C++, and supply a default constructor function.

Or if you're stuck with C, then your approach is one of several roughly equal approaches.
None of which would be as elegant as using C++.
Contributor
15Jan2008,15:27   #3
technosavvy's Avatar
if you want to initialize everything with a zero...
u can go for
Code:
employee emp1 = {0};
..
Newbie Member
15Jan2008,20:11   #4
drichird's Avatar
Quote:
Originally Posted by technosavvy
if you want to initialize everything with a zero...
u can go for
Code:
employee emp1 = {0};
..
Of course I cannot use C++ (must be pure C) or question would be trivial. Thanks technosavvy, I will just zero out all fields as you suggest, makes it a little cleaner.