Re: opaque style question

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 04/18/04


Date: Sat, 17 Apr 2004 22:12:52 -0400 (EDT)


On Sat, 17 Apr 2004, Joe Wright wrote:
>
> We may be going sideways here. I was responding to Dan's conjecture
> on whether FILE could/should be incomplete so as to be opaque. While
> you can declare a pointer to incomlete struct type, it would be
> problematic to assign meaningful values to such pointers.

  No, it wouldn't. Look, what do you do with C's objects of type
'FILE *' at the moment? You can:

    - Assign predefined values to them: fp = stdin;
    - Assign new values to them: fp = fopen(...);
    - Pass them to functions: fclose(fp);
    - Pass their addresses to functions: my_open(&fp);
    - Compare them for equality: if (fp == stdin) ...
    - Compare them to predefined values: if (fp == NULL) ...

What other meaningful operations on file descriptors can you think
of?* Note that all of the above operations could be done whether
FILE were an opaque type or not. As it happens, FILE is *not* an
opaque type, but I agree with Dan Pop here --- there's no practical
reason for the Standard to say it mustn't be. It looks like just
one of C's "quirks."

-Arthur

[*] - I know the phrase "file descriptor" usually means something
else on Unixoid systems, but if I said "file-describer," I'd get
responses correcting my English. ;-) Standard C, as far as I know,
doesn't use the term "file descriptor" to mean either an integer
*or* a [pointer to a] FILE object.



Relevant Pages

  • Erradic/epileptic mouse behavior - Help!
    ... suddenly the mouse pointer is all over the screen. ... Like an epileptic system operator is in charge. ... arrow freezes and the mouse isn't responding. ... reboot I sometimes regain control of the mouse, ...
    (microsoft.public.windowsxp.hardware)
  • Un-controled Erratic/epileptic mouse movement/clicking
    ... suddenly the mouse pointer is all over the screen. ... Like an epileptic system operator is in charge. ... arrow freezes and the mouse isn't responding. ... reboot I sometimes regain control of the mouse, ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Just how delicate are freed pointers?
    ... >> You should read a thread before responding. ... but some will have trap values that trigger when an invalid ... >> pointer is used in a calculation. ...
    (comp.lang.c)
  • Re: Exporting/importing a variable from a Dll
    ... Thanks for responding, your're right about the casting, so I cleaned that ... And in the dll I made a pointer to an integer, which allowed me to set it to ...
    (microsoft.public.vc.mfc)
  • Re: [Lit.] Buffer overruns
    ... >can be caught by proper design; the opaque type ... >ought to be a handle, not a direct data pointer: ...
    (sci.crypt)