3 ms·
My preference is for A. That said, I am considering using the following form, which allows the self MyGraph pointer to be null, and will cause the constructor t
by lesserknowndan 4y ago
My preference is for A. That said, I am considering using the following form, which allows the self MyGraph pointer to be null, and will cause the constructor to allocate the space required.
This also allows the constructor to be called by some other function that wants it to initialise some pre-allocated memory.
MyGraph*
MyGraph_New( MyGraph* self, const char* name, const Matrix* m )
{
if ( !self ) self = calloc( 1, sizeof( MyGraph ) );
if ( self )
{
self->name = strdup( name );
self->matrix = Matrix_copy( m );
}
return self;
}