I got a simple quesiton; I am using a FILE* fp
in one of my libraries to fopen/fwrite开发者_JS百科
to the file, and I want to do fclose()
on fp
in another library - what is the best way for the other library to get the file handle?
If your two libraries talk to each other then the first should pass the FILE*
to the second in a function call.
If the libraries don't talk to each other then the main application should get the FILE*
from the first library and hand it to the second library. Or better, the application should own the FILE*
, hand it to the first library already opened, and then hand it to the second library to be finished off, and finally the application should close the FILE*
itself. Trying to deal with a library that wants a filename instead of a FILE*
can be very frustrating when you have something that is like a file but doesn't have a name.
精彩评论