Skip to content

Commit 61d34a3

Browse files
starseekercshorler
authored andcommitted
Add some default initializers in the generated C++ code.
1 parent 6c9a258 commit 61d34a3

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/exp2cxx/classes_attribute.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,24 @@ void DataMemberPrintAttr( Entity entity, Variable a, FILE * file ) {
130130
fprintf( stderr, "Warning: in entity %s, the type for attribute %s is not fully implemented\n", ENTITYget_name( entity ), attrnm );
131131
}
132132
if( TYPEis_entity( VARget_type( a ) ) ) {
133-
fprintf( file, " SDAI_Application_instance_ptr _%s;", attrnm );
133+
fprintf( file, " SDAI_Application_instance_ptr _%s = NULL;", attrnm );
134134
} else if( TYPEis_aggregate( VARget_type( a ) ) ) {
135-
fprintf( file, " %s_ptr _%s;", ctype, attrnm );
135+
fprintf( file, " %s_ptr _%s = NULL;", ctype, attrnm );
136136
} else {
137-
fprintf( file, " %s _%s;", ctype, attrnm );
137+
Class_Of_Type class = TYPEget_type(VARget_type(a));
138+
switch (class) {
139+
case boolean_:
140+
fprintf(file, " %s _%s = false;", ctype, attrnm);
141+
break;
142+
case integer_:
143+
fprintf(file, " %s _%s = 0;", ctype, attrnm);
144+
break;
145+
case real_:
146+
fprintf(file, " %s _%s = 0.0;", ctype, attrnm);
147+
break;
148+
default:
149+
fprintf(file, " %s _%s;", ctype, attrnm);
150+
}
138151
}
139152
if( VARget_optional( a ) ) {
140153
fprintf( file, " // OPTIONAL" );

0 commit comments

Comments
 (0)