> Is there no way to provide default initialization for structure members in c?
Well there's no automatic way - that's what c++ does.
However, you can do something like this
Code:
struct MyType {
int x;
int y;
};
// data - if all members are static
struct MyType initMyType = { 0, 0 };
// function - if some members are dynamic
// like allocating space
struct MyType initMyType ( void ) {
struct MyType result;
result.x = 0;
result.y = 0;
return result;
}
When you declare a variable, it would go something like this.
struct MyType var1 = initMyType;
or
struct MyType var2 = initMyType();