From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-05-06 12:08:04
Hi! On Tue, May 06, 2003 at 11:50:06AM +0200, Spiro Trikaliotis wrote: > Just out of curiosity: What are void data structures good for? I can't see > any use of this, but I'm open for any hints. > > I'm sorry for this "C course" question. It's not a "C course" question, because it is a non standard feature. void data structures allows one to define arbitrary data. For example, there is no easy way to define a structure that is equivalent to the following asm code: table: .word 0 .asciiz "foobar" .word 1 .asciiz "baz" .word 2 .asciiz "lxsh" Two ways to work around this are: 1. Define a struct like struct tabledata { unsigned num; char id[8]; }; and live with the overhead generated by the strings, or 2. use a character buffer and encode the data structure byte by byte: unsigned char tabledata[] = { 0, 0, 'f', 'o', 'b', 'a', 'r', '\0', 1, 0, 'b', 'a', 'z', '\0', ... }; If you have an API that expects such a data structure as an argument, you cannot use 1. The remaining possibility (2.) is ugly and gets even more ugly if the data structure is more complex. GEOS is an example for an application that has an API with data structures like the one above. Forcing people to define their data structures like in 2. would be a nice way to get them upset very quickly, so I added void data variables. Since the data type is "void" it cannot be accessed directly. But, when taking a pointer to this variable, it automatically yields a "void*", which can be passed to every function that expects any pointer. Regards Uz -- Ullrich von Bassewitz uz_at_musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-05-06 12:08:18 CEST