From: Carlo W. <li...@us...> - 2002-02-17 15:30:27
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-01-17 15:30:25 UTC Modified files: libcwd/documentation/doxygen-examples/markers.cc libcwd/documentation/tutorial/channel.cc libcwd/documentation/tutorial/faq.m4 libcwd/documentation/tutorial/hello_world.cc libcwd/documentation/tutorial/log_file.cc libcwd/documentation/tutorial/tut1.m4 libcwd/documentation/tutorial/tut2.m4 libcwd/documentation/tutorial/tut3.m4 libcwd/documentation/tutorial/tut5.in libcwd/documentation/tutorial/tut6.m4 Log message: Fixes for _GNU_SOURCE. Put even more stress on using custom debug.h and sys.h in the tutorial. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/doxygen-examples/markers.cc diff -u src/libcwd/documentation/doxygen-examples/markers.cc:1.3 src/libcwd/documentation/doxygen-examples/markers.cc:1.4 --- src/libcwd/documentation/doxygen-examples/markers.cc:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/doxygen-examples/markers.cc Sun Feb 17 07:30:14 2002 @@ -1,4 +1,6 @@ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include <libcw/sysd.h> #include <libcw/debug.h> Index: src/libcwd/documentation/tutorial/channel.cc diff -u src/libcwd/documentation/tutorial/channel.cc:1.3 src/libcwd/documentation/tutorial/channel.cc:1.4 --- src/libcwd/documentation/tutorial/channel.cc:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/tutorial/channel.cc Sun Feb 17 07:30:15 2002 @@ -2,16 +2,23 @@ // Please see the "example-project" in the source distribution of libcwd // for a better Real Life example. +//------------------------------------------------------------------------------- +// This block should really be part of custom header files! Please ignore it +// and read documentation/html/preparation.html#preparation_step2 instead. +// "sys.h": +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include <libcw/sysd.h> #define DEBUGCHANNELS ::example // Where we'll put our namespace dc +// "debug.h": #include <libcw/debug.h> - namespace example { // namespace dc cannot be put in :: namespace dc { libcw::debug::channel_ct ghost("GHOST"); // Create our own Debug Channel } } +//------------------------------------------------------------------------------- int main(void) { Index: src/libcwd/documentation/tutorial/faq.m4 diff -u src/libcwd/documentation/tutorial/faq.m4:1.5 src/libcwd/documentation/tutorial/faq.m4:1.6 --- src/libcwd/documentation/tutorial/faq.m4:1.5 Thu Feb 14 15:32:12 2002 +++ src/libcwd/documentation/tutorial/faq.m4 Sun Feb 17 07:30:15 2002 @@ -24,9 +24,11 @@ what could possibly be wrong with your code. Once the application works, you don't have to define _GNU_SOURCE because you won't be including the debug code anymore, nor link with -libcwd. Of course, when you are not sure whether or not new code -that you added is a GNU extension or not, you should try to compile it -with CWDEBUG undefined.</P> +libcwd. If you need to write 100% ANSI code and you are not sure +whether or not new code that you added is an extension or not, you +should try to compile it with CWDEBUG undefined <EM>and</EM> using -ansi as +command line option to g++; without -ansi g++-3.0.3 and higher define +_GNU_SOURCE itself by default.</P> <A name="sysd.h"></A> <H3>2. Why do I have to include "libcw/sysd.h" as first header file?</H3> Index: src/libcwd/documentation/tutorial/hello_world.cc diff -u src/libcwd/documentation/tutorial/hello_world.cc:1.3 src/libcwd/documentation/tutorial/hello_world.cc:1.4 --- src/libcwd/documentation/tutorial/hello_world.cc:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/tutorial/hello_world.cc Sun Feb 17 07:30:15 2002 @@ -1,6 +1,14 @@ +//------------------------------------------------------------------------------- +// This block should really be part of custom header files! Please ignore it +// and read documentation/html/preparation.html#preparation_step2 instead. +// "sys.h": +#ifndef _GNU_SOURCE // g++ 3.0.3 and higher already define this. #define _GNU_SOURCE -#include <libcw/sysd.h> // This must be the first header file +#endif +#include <libcw/sysd.h> // This must be the first header file +// "debug.h" #include <libcw/debug.h> +//------------------------------------------------------------------------------- int main(void) { Index: src/libcwd/documentation/tutorial/log_file.cc diff -u src/libcwd/documentation/tutorial/log_file.cc:1.3 src/libcwd/documentation/tutorial/log_file.cc:1.4 --- src/libcwd/documentation/tutorial/log_file.cc:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/tutorial/log_file.cc Sun Feb 17 07:30:15 2002 @@ -1,7 +1,15 @@ +//------------------------------------------------------------------------------- +// This block should really be part of custom header files! Please ignore it +// and read documentation/html/preparation.html#preparation_step2 instead. +// "sys.h": +#ifndef _GNU_SOURCE // g++ 3.0.3 and higher already define this. #define _GNU_SOURCE -#include <libcw/sysd.h> -#include <fstream> +#endif +#include <libcw/sysd.h> // This must be the first header file +// "debug.h" #include <libcw/debug.h> +//------------------------------------------------------------------------------- +#include <fstream> int main(void) { Index: src/libcwd/documentation/tutorial/tut1.m4 diff -u src/libcwd/documentation/tutorial/tut1.m4:1.6 src/libcwd/documentation/tutorial/tut1.m4:1.7 --- src/libcwd/documentation/tutorial/tut1.m4:1.6 Thu Feb 14 21:19:32 2002 +++ src/libcwd/documentation/tutorial/tut1.m4 Sun Feb 17 07:30:15 2002 @@ -13,8 +13,10 @@ <P>Compile as: <SPAN class="shell-command">g++ -g -DCWDEBUG hello_world.cc -lcwd -o hello_world</SPAN></P> <PRE> -// These two lines should actually be part of a custom "sys.h" file. See <A HREF="tut2.html">tutorial 2</A>. +// These four lines should actually be part of a custom "sys.h" file. See <A HREF="tut2.html">tutorial 2</A>. +#ifndef _GNU_SOURCE // Already defined by g++ 3.0.3 and higher. #define _GNU_SOURCE // This must be defined before including <libcw/sysd.h> +#endif #include <libcw/sysd.h> // This must be the first header file // This line should actually be part of a custom "debug.h" file. See <A HREF="tut2.html">tutorial 2</A>. #include <libcw/debug.h> @@ -42,7 +44,10 @@ Note that you only really have to define it when you compiled libcwd with threading support. If you do not define this macro and libcwd needs it, then you will get -a compile error in <libcw/sysd.h> telling you so.</P> +a compile error in <libcw/sysd.h> telling you so. +GNU gcc 3.0.3 (and higher) already defines this macro by itself, so there is +no need to include it if you intend to only compile your application with +this version.</P> <DIV class="faq-frame"><H4>FAQ</H4><UL class="faq"> <LI><A HREF="faq.html#GNU_SOURCE">Won't this define make my code non-portable?</A></LI> Index: src/libcwd/documentation/tutorial/tut2.m4 diff -u src/libcwd/documentation/tutorial/tut2.m4:1.4 src/libcwd/documentation/tutorial/tut2.m4:1.5 --- src/libcwd/documentation/tutorial/tut2.m4:1.4 Thu Feb 14 15:32:12 2002 +++ src/libcwd/documentation/tutorial/tut2.m4 Sun Feb 17 07:30:15 2002 @@ -16,11 +16,12 @@ #ifdef HAVE_CONFIG_H // This is just an example of what you could do #include "config.h" // when using autoconf for your project. #endif -#ifdef CWDEBUG // This is needed so that others can compile -#ifndef _GNU_SOURCE -#define _GNU_SOURCE +#ifdef CWDEBUG // This is needed so that others can compile + // your application without having libcwd installed. +#ifndef _GNU_SOURCE // Already defined by g++ 3.0.3 and higher. +#define _GNU_SOURCE // Needed for libpthread extensions. #endif -#include <libcw/sysd.h> // your application without having libcwd installed. +#include <libcw/sysd.h> #endif </PRE> <P>Create a file <CODE>"debug.h"</CODE> that is part of your application and put in it:</P> @@ -78,13 +79,10 @@ #include "sys.h" #include "debug.h" -// Include this to make life easier. -using namespace libcw::debug; - // Actual definition of `ghost' namespace debug_channels { namespace dc { - channel_ct <SPAN class="highlight">ghost</SPAN>("GHOST"); + libcw::debug::channel_ct <SPAN class="highlight">ghost</SPAN>("GHOST"); } } Index: src/libcwd/documentation/tutorial/tut3.m4 diff -u src/libcwd/documentation/tutorial/tut3.m4:1.3 src/libcwd/documentation/tutorial/tut3.m4:1.4 --- src/libcwd/documentation/tutorial/tut3.m4:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/tutorial/tut3.m4 Sun Feb 17 07:30:15 2002 @@ -13,10 +13,9 @@ <P>Compile as: <CODE>g++ -DCWDEBUG log_file.cc -lcwd -o log_file</CODE></P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> +#include "sys.h" // See tutorial 2. #include <fstream> -#include <libcw/debug.h> +#include "debug.h" // See tutorial 2. int main(void) { Index: src/libcwd/documentation/tutorial/tut5.in diff -u src/libcwd/documentation/tutorial/tut5.in:1.3 src/libcwd/documentation/tutorial/tut5.in:1.4 --- src/libcwd/documentation/tutorial/tut5.in:1.3 Thu Feb 14 15:32:13 2002 +++ src/libcwd/documentation/tutorial/tut5.in Sun Feb 17 07:30:15 2002 @@ -30,8 +30,8 @@ <P class="download">[<A HREF="examples5/test5.1.1.cc">download</A>]</P> <PRE> <!-- START CODE examples5/test5.1.1.cc --> -#include "sys.h" // See tutorial 2 -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2 +#include "debug.h" int main(void) { Index: src/libcwd/documentation/tutorial/tut6.m4 diff -u src/libcwd/documentation/tutorial/tut6.m4:1.3 src/libcwd/documentation/tutorial/tut6.m4:1.4 --- src/libcwd/documentation/tutorial/tut6.m4:1.3 Thu Feb 7 20:03:47 2002 +++ src/libcwd/documentation/tutorial/tut6.m4 Sun Feb 17 07:30:15 2002 @@ -59,9 +59,8 @@ <P>Compile as: <CODE>g++ -DCWDEBUG amo.cc -lcwd -o amo</CODE></P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -85,9 +84,8 @@ <P>Now let us actually allocate some memory:</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -117,9 +115,8 @@ In order to find out what is wrong, we <EM>also turn on debug channel</EM><CODE> dc::bfd</CODE>:</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -183,9 +180,8 @@ your program is doing:</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -219,9 +215,8 @@ <P>Consider the following code:</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -259,9 +254,8 @@ <CODE>AllocTag_dynamic_description()</CODE>, which <EM>will</EM> work.</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { @@ -305,9 +299,8 @@ <CODE>AllocTag1(p)</CODE>:</P> <PRE> -#define _GNU_SOURCE -#include <libcw/sysd.h> -#include <libcw/debug.h> +#include "sys.h" // See tutorial 2. +#include "debug.h" int main(void) { ----------------------- End of diff ----------------------- |