[TAG] Everything you ever wanted to know about C types, Part 1: What's in a type?

Jimmy O'Regan jimregan at o2.ie
Fri Jan 6 02:39:03 MSK 2006


http://www-128.ibm.com/developerworks/power/library/pa-ctypes1/?ca=dgr-lnxw02CTypesP1

"It is also possible to provide an incomplete definition of a structure 
or union type, providing the tag name but not the contents. Such an 
incomplete type cannot be directly used, but pointers to such a type can 
be used (but not dereferenced). You can use this to provide a level of 
encapsulation many people don't realize is possible in C.

Listing 3. Encapsulation in C.

	/* foo.h */
	struct foo_hidden;
	typedef struct foo_hidden *foo;
	extern foo new_foo();
	extern void delete_foo(foo);

	/* foo.c */
	struct foo_hidden {
		/* contents go here */
	};

... the <stdio.h> API never manipulates a FILE object directly, only 
pointers to FILE objects. In fact, such systems are entirely conforming. 
The humorous "Your stdio doesn't appear very std." message that Perl's 
Configure script emits when it can't figure out how to poke around 
inside a private structure is simply false."






More information about the TAG mailing list