12/2/2023 0 Comments Opaque transparent![]() ![]() ![]() When you compile prog1.c and prog2.c into a single executable and run it, the output is: xyzzyOpen payload = 42Īs you would expect from the main function. The printf calls are there simply to show that it can use the internals, and you'd probably want to add checking of the return value from malloc in production-ready code but that's not relevant to the purpose of this example. Printf ("xyzz圜lose payload = %d\n", plugh->payload) Printf ("xyzzyOpen payload = %d\n", plugh->payload) Struct xyzzy *plugh = malloc (sizeof (struct xyzzy)) Xyzz圜lose (num3) // these two intentionallyĪnd the implementation of the calls, prog2.c, actually controls and knows the internals, so can use them quite freely: #include Now you can quite happily use those functions from a program prog1.c without knowing the internals of the structure: #include "prog2.h" Prog1.c:3:15: error: storage size of 'myvar' isn't known Would cause an error along the lines of: prog1.c: In function ‘main’: Note that pointers to an incomplete type are fine but you cannot instantiate an object of that type since you don't know its internals. This is all that clients of the code see, an incomplete type struct xyzzy and some functions to allocate and release objects of that type (they don't get to see prog2.c detailed below). Consider the following header file prog2.h for obtaining and releasing xyzzy objects: struct xyzzy Opaque pointers, done correctly, should reveal no information other than the type name itself and you can implement that in C relatively easily. Opacity requires the information to be hidden rather than just enacting a "gentleman's agreement" not to use it. Opacitya is a graphics directive that specifies that graphical objects that. Note that part of the definition at the front: "not able" rather than "not willing". That's fine as long as people stick to the rules, only passing such values to functions like fread() and fclose() but the problem with revealing information is that people sometimes (foolishly) begin to rely on it.įor example, glibc publishes its FILE structure (as struct _IO_FILE) in libio.h so that type is not technically opaque. People often use the C type FILE as the classic example but often this is not opaque - the details are revealed in stdio.h for anyone to see and they simply rely on the user of the type to not fiddle with the internals. ![]() transmitting light able to be seen through with clarity the cold crystalline water of melted snow. Impervious to the rays of light not transparent as, an opaque substance. In Computer Science, this means a value which reveals no details other then the type of the value itself. Admitting the passage of light open porous as, a transparent veil. "Opaque" is defined, in English, as "not able to be seen through not transparent". ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |