is python Object oriented??
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Wed Feb 4 04:11:22 EST 2009
thmpsn.m.k at gmail.com a écrit :
> On Feb 3, 1:14 am, David Cournapeau <courn... at gmail.com> wrote:
(snip)
>> after all, we have used FILE* for years and I have no idea about the FILE
>> structure.
>
> Your lack of knowledge about it doesn't mean that it has somehow
> magically "private" members. The only reason that most of us don't
> know what a FILE is is that it's definition is implementation-defined
> (i.e., every compiler may define it differently).
>
> That doesn't have anything to do with private members. For example, on
> my system, <stdio.h> defines FILE as:
>
> struct _iobuf {
> char *_ptr;
> int _cnt;
> char *_base;
> int _flag;
> int _file;
> int _charbuf;
> int _bufsiz;
> char *_tmpfname;
> };
Didn't you notice kind of a pattern here ?
> typedef struct _iobuf FILE;
>
> Given this information, nothing prevents me from writing things like:
>
> FILE* fp = fopen("file.txt", "r");
> if (!fp) { /* do something */ }
>
> printf("fp->_cnt = %d\n", fp->cnt);
> printf("fp->_flag = %d\n", fp->_flag);
> printf("fp->_file = %d\n", fp->_file);
>
> fp->_flag = 0x20; // OOPS!!
Indeed - and that's exactly the point : nothing prevents you from
accessing the implementation, *and yet, you don't* - unless of course
you have a very strong reason to do so for a very specific corner case
*and* you pretty well know what you're doing *and* you accept the
implications.
More information about the Python-list
mailing list