Iโve been developing in C for a while, coming from object-oriented languages โโlike C ++ and Java, and using standard library functions like fread() and strtok() , I began to wonder how these functions go about storage variables related to their state?
For example, strtok() behaves differently for subsequent calls, and fread() tracks your position in the file. This information should be stored somewhere, and in an object-oriented language, there are area constructs such as private or protected to protect these values โโfrom undesirable modification, but as I understand it, C does not have these.
So how are they stored safely? Or are they really global and can be changed anywhere? The question arose when I wrote a header file with utility functions that were supposed to store similar status information. What is the โrightโ way to do things like this in C, and how are they handled in existing libraries?
source share