delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/02/21:32:40

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Multipal files
Date: Fri, 01 Aug 1997 08:50:11 -0700
Organization: Alcyone Systems
Lines: 70
Message-ID: <33E205B3.2068A15@alcyone.com>
References: <1 DOT 5 DOT 4 DOT 16 DOT 19970727141648 DOT 54175b30 AT giasbga DOT vsnl DOT net DOT in> <5rrqo2$5co AT freenet-news DOT carleton DOT ca>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Paul Derbyshire wrote:

> For every module with classes other modules use, and code as well, make
> a
> .cc and a .h file. In the .h file are some parts:

My personal style is to name C++ header files .hh, but fine so far.

> Then I have this:
> 
> #ifndef _PGD_FOO_CC_
> 
> extern int bar,baz;
> extern double quux;
> 
> #endif
> 
> to declare the global variables. In the .cc I declare _PGD_FOO_CC_ and
> thus
> the variables don't get double declared.

Uh?  What problem is there with variables getting double-declared?  The
standard way to do is to declare them in the header:

    extern int bar;

and define them in the source file:

    int bar;

Provided the header is wrapped in the preprocessing statements that
prevent double inclusion, there's no way that this can be double
declared/defined, unless you're linking in that module _twice_, which
would be asking for it anyway.

> The .cc has comments like the .h, then global variables and any class
> variables, as in

I don't see what the purpose of this is, unless you're .cc file contains a
template.

> static int fooclass::foovar=0;

Minor (well, minor to your main point here) nitpick:  Static members are
_declared_ with the static keyword, but not defined with one, viz.:

    class C
    {
        // ...
        static int i;
        static int f(void);
        // ...
    };

    // ...

    int C::i = 0;
    int C::f(void) { /* ... */ }

Note that putting the static keyword in the definition is an error (gcc
complains, "static member '...' re-declared as static" or "cannot declare
member function '...' to have static linkage."

-- 
       Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
   "Love is not love which alters / when it alternation finds."
                                 / William Shakespeare, _Sonnets_, 116

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019