bug-gnulib
[Top][All Lists]
Advanced

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

Re: question about correct usage of gnulib


From: Lorenzo Bettini
Subject: Re: question about correct usage of gnulib
Date: Mon, 02 May 2011 12:02:06 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8

On 04/25/2011 06:36 PM, Bruno Haible wrote:
Lorenzo Bettini wrote:
on the manual I read

"These Gnulib substitute header files rely on<config.h>  being already
included. Furthermore<config.h>  must be the first include in every
compilation unit. This means that to all your source files and likely
also to all your tests source files you need to add an ‘#include
<config.h>’ at the top. Which source files are affected? Exactly those
whose compilation includes a ‘-I’ option that refers to the Gnulib
library directory. "

This paragraph is correct.

Would it be correct to put config.h only say in file1.cpp (and use the
‘-I’ option that refers to the Gnulib library directory for that file
only), and not in file2.cpp and file3.cpp (where I don't use -I to refer
to gnulib library directory), and then link all the 3 files together by
also putting -lgnu?

This will work find as long as data types defined in system headers defined by
gnulib (such as structs, function pointers, pointers to socklen_t, etc.) are
not exchanged between file1.cpp on one side and file2.cpp and file3.cpp on the
other side.

For example, if file1.cpp passes a 'struct stat' to file2.cpp through some
function call or global variable, then you must be aware that the 'struct stat'
that file1.cpp sees is 64-bit safe and therefore larger than the 32-bit
'struct stat' that file2.cpp sees. Similarly for 'struct sched_param' in
<sched.h>  and others. Typically this leads to crashes that are very hard to
debug because the source code suggests to you that the two 'struct stat's
are the same when they are not.

Thanks for the answer

but what about libraries?
For instance, I can live with including config.h in all .cpp library files, but I wouldn't add it to library header files. Header files are not referring to any struct defined in system header files of gnulib... at least I guess (basically my library header files only use string form C++ standard library)... would that be safe?

thanks
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com





reply via email to

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