« first day (1728 days earlier)      last day (1894 days later) » 

4:22 PM
Why is this if conditional like this? if(conn->file) fclose(conn->file); what if conn is created but not initialized? conn->file will have random value.
 
@Moytaba Not enough context to know.
 
@Moytaba not initialized will lead fclose(conn->file) to be undefined behavior.
 
@dbush this is a very simple database code and the part of code I sent is in the beginning of the Database_close function.
 
4:40 PM
@Moytaba So is sounds like the function has a precondition that conn is valid.
 
@dbush If that is the case, why is there an "if(conn)" just in the line before that?
 
@Moytaba Well then there's your check.
 
@dbush Sorry I don't understand :) I haven't added anything to the code. I've posted the link to it above.
I mean even if a connection is not created, since conn is just a random pointer, it will evaluate to true in if(conn)
 
5:45 PM
@Moytaba The only place Database_close is called is after Database_open, and that function returns a valid conn and conn->file.
 
 
1 hour later…
7:08 PM
@dbush So those ifs actually are unnecessary?!
(Thanks for your time)
 
@Moytaba They should be there, since you want to make sure you don't have a null pointer. However, there's no way in general to distinguish between a valid pointer and a non-null invalid pointer.
 
@dbush Great point! Thank you very much.
I'm curious to know how the "rewind" function works. I guess there are extra information within a FILE structure when the stream is created so with that rewind can specifiy where a file starting point is. Right?!
 

« first day (1728 days earlier)      last day (1894 days later) »