[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lzip-bug] include pthread.h in plzip.cc
From: |
Ersek, Laszlo |
Subject: |
Re: [Lzip-bug] include pthread.h in plzip.cc |
Date: |
Tue, 19 Jan 2010 20:43:16 +0100 (CET) |
On Tue, 19 Jan 2010, Antonio Diaz Diaz wrote:
It seems the line:
#include <pthread.h>
needs to be inserted at line 29 of plzip.cc.
That depends on personal taste. (Pertinently enough, a conversation
concerning this taste is just running in the comp.lang.c Usenet newsgroup,
see [0].)
a) One approach is to #include headers only in .c (or .cc) files, and
forbid recursive inclusion, ie. #include preprocessing directives in
headers. Each .c (.cc) file is responsible for collecting all necessary
declarations (and in the right order) from the appropriate headers.
b) Another approach (which I profess mine) is to provide everything
necessary (and nothing more) in a header so that the declarations
providing the reason d'etre for the header can be immediately used. For
example, if you #include <stdlib.h> for malloc(), you expect size_t
(parameter type of malloc()) to become visible; you don't want to have to
#include <stddef.h> too.
"main.h" declares struct Cond, and struct Cond has a member of type
pthread_mutex_t. Approach "b" says: let's #include <pthread.h> in
"main.h", so that whoever tries to define (allocate) a struct Cond object,
he/she can do that without further #include's. "plzip.cc" depends on
"main.h" and rightfully so, it defines (allocates) struct Cond objects.
When looked at under approach "b", the #include is missing from "main.h"
(it was there in llzip-0.03 :)).
According to approach "a", the #include directive should be added to
"plzip.cc". "main.cc" (also dependent on "main.h") does include
<pthread.h> before the inclusion of "main.h", hence it indeed reflects
approach "a" (which is perfectly fine if used consistently, just not my
taste (which doesn't matter, since Antonio is the maintainer (and more and
more, principal author) of plzip)). I reckon he likes approach "a" (*) and
converted the source to it, and missed this single inclusion.
(*) For example, "arg_parser.h" employs std::string but doesn't include
<string> (or anything else). "arg_parser.cc" does.
Cheers,
lacos
[0]
http://groups.google.com/group/comp.lang.c/browse_frm/thread/8ac1309e95a1004a/24ca4109ea30be04?tvc=1#24ca4109ea30be04