On Fri, 11 Dec 2009, Antonio Diaz Diaz wrote:
Hello list,
Jacob Rief wrote:
Why don't you declare a zero sized
C-struct, say struct LZ_Decoder {}; and struct LZ_Encoder {};
Those are empty structures, not zero sized structures.
a) C99, 6.5.3.4 The sizeof operator, EXAMPLE 2: "Another use of the sizeof
operator is to compute the number of elements in an array":
sizeof array / sizeof array[0]
b) http://www2.research.att.com/~bs/bs_faq2.html#sizeof-empty
Why is the size of an empty class not zero?
To ensure that the addresses of two different objects will be different.
rewrite the prototypes of the functions to expect a pointer onto these
dummy structs. This would make the code of the lzlib clients a lot
typesafer, so that mixing up a decoder with an encoder is detected
during compile time instead of runtime.
What do you think about this change? Should I use a typedef so that C
programs can declare variables this way:
LZ_Encoder * encoder;
instead of the standard C
struct LZ_Encoder * encoder;
?
I believe that "bringing out" structure tags into the ordinary identifier
namespace via typedefs is bad style in C. Personal preferences aside, both
libz and libbz2 do that, so you might want to follow their convention.
http://www.zlib.net/manual.html#struct%20z_stream_s
http://bzip.org/1.0.5/bzip2-manual-1.0.5.html#bzcompress-init
Cheers,
lacos
_______________________________________________
Lzip-bug mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lzip-bug