Why 'void *' is useful

ado at elsie.UUCP ado at elsie.UUCP
Wed Jul 11 11:16:21 AEST 1984


>	A non-sensical use of 'void' would be to declare an object of type void
>	(not function-returning-void). e.g.
>	f() {
>		void x;	/* Now what do I do with it? */
>		...
>	}

What do you do with it?  Take "sizeof x", of course. :-)

A possibly sane use would be as a place-holder for "obsolete"
elements of structures stored in files.  Suppose you have a bunch of
files, each of which contains a structure like:

	typedef struct {
		int	fortran;
		int	pascal;
		int	c;
	} languages;

Now suppose you want to stop using "fortran" and "pascal", and yet want to be
able to retrive the information in the "c" element of previously-stored
structures.  You might want to:

	typedef struct {
		void int	fortran;
		void int	pascal;
		int		c;
	} languages;

to enforce discontinuation of use of the "obsolete" elements while preserving
the ability to get at the "c" elements in the files.  Currently, you can
do this by declaring unnamed bit fields; doing this is machine dependent, given
the varying number of bits per int (or whatever) on different machines.

Of course, it STILL doesn't make sense in the above example for "void" to stand
alone--here, it's being used as an adjective.
--
	...decvax!allegra!umcp-cs!elsie!ado	(301) 496-5688
	(the DEC and VAX in decvax are Digital Equipment Corporation trademarks)



More information about the Comp.lang.c mailing list