lzip-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Lzip-bug] Restarting an lzip member at any time


From: Ersek, Laszlo
Subject: Re: [Lzip-bug] Restarting an lzip member at any time
Date: Fri, 11 Dec 2009 20:35:17 +0100 (CET)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]