Topic: Declaration headers.


Author: Attila Feher <Attila.Feher@lmf.ericsson.se>
Date: Wed, 26 Jun 2002 16:34:33 GMT
Raw View
Jerry Don Fisher Jr wrote:
[SNIP]
> #ifndef _MACRO_DEFINED_IN_HEADER_TO_BE_INCLUDED
[SNIP]
> #define _A_MACRO_FOR_THIS_HEADER

Not really, as far as I understood the reserved names in standard C++:
names beginning with an underscore followed by an uppercase letter are
reserved to the implementation...  So I would not use a begining _ here.

Attila

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Jerry Don Fisher Jr <jerryf1@mail.attbi.com>
Date: 22 Jun 2002 16:57:52 GMT
Raw View
Thaddeus L Olczyk wrote:

> Something just occured to me. It may be very stupid, but I think
> it may make some sense with some work.
>
> In C++ we have cyclical dependencies principly because
> we include code in headers.

The solution is simpler.  DO NOT include CODE in headers.  I learned that
rule the first Time I tryed to learn C/C++ ten years ago.  The code goes
into seperate source files that then include the header to compile into a
linkable object files.  You then include the header (which only contains
declarations) in your file and link against the object files.

include structures such as

#ifndef _MACRO_DEFINED_IN_HEADER_TO_BE_INCLUDED
#include "header_to_be_included"
#endif

in your headers and do not forget to

#define _A_MACRO_FOR_THIS_HEADER

at the end of each header for use in other files.  I learned this from
reading the headers included with my compilers.  It seems to work great for
breaking the cycles.

If there is something I do not understand about your post and I am not
responding to what you ment to say then I am sorry.  I am not a
professional programer at this point only an amituar trying to move that
direction.


--
If I had something importaint to say I would have mumbled it.



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]






Author: allan_W@my-dejanews.com (Allan W)
Date: 22 Jun 2002 16:57:52 GMT
Raw View
Thaddeus L Olczyk <olczyk@interaccess.com> wrote
> In C++ we have cyclical dependencies principly because
> we include code in headers.

OH! That's the reason?

> So it may be a good idea for the standard to specify a new
> type of header, extra to other headers, which I call a declaration
> header.

In C and C++, there's a special name for a source module that
contains declarations but not code. We call them header files.
The usual naming convention is to use a ".h" suffix on the names
of all header files; thus, I would expect "foo.h" to contain
exactly what you want "foo.d" to contain.

> The basic idea is this.
> You write the standard header, call it foo.h.
> The compiler is required to generate a foo.d
> ( perhaps this should be automatic, perhaps it
> should be a comand line option ).
> In other headers which require the declarations
> in foo.h but not the code, one can
> then include foo.d.
>
> Since these headers don't also include code they
> don't generate cyclical dependencies.

What do you mean by cyclical dependencies? For most of us, this
means code like this:
    class Employee {
        // ...
        Department * m_dept; // Employee's department
    };
    class Department {
        // ...
        vector<Employee> m_employees; // All employees in this department
    };

This could happen in two header files or even in just one.
The "solution" to this problem is to use forward declarations;
put this line
    class Department;
before the declaration of class Employee.

> I base this on the basic idea that the major technique
> to break cyclical dependencies is:
>
> to change
> #include "foo.h"
>
> ....
>
> to
>
> class foo;

Maybe I'm so stupid that I missed your point completely, and I've
tried to help you solve some other problem completely!

Or maybe you've got code in your header files, that should be
moved into traditional source files.



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]






Author: Thaddeus L Olczyk <olczyk@interaccess.com>
Date: 19 Jun 02 22:11:38 GMT
Raw View
Something just occured to me. It may be very stupid, but I think
it may make some sense with some work.

In C++ we have cyclical dependencies principly because
we include code in headers.

So it may be a good idea for the standard to specify a new
type of header, extra to other headers, which I call a declaration
header.

The basic idea is this.
You write the standard header, call it foo.h.
The compiler is required to generate a foo.d
( perhaps this should be automatic, perhaps it
should be a comand line option ).
In other headers which require the declarations
in foo.h but not the code, one can
then include foo.d.

Since these headers don't also include code they
don't generate cyclical dependencies.

I base this on the basic idea that the major technique
to break cyclical dependencies is:

to change
#include "foo.h"

....

to

class foo;

It seems that the compiler should be able to automate such tasks for
you. So suggestiongs on whats wrong with this iea and how to fix it?

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]