Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #8042

Re: #define - in header or cpp

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: #define - in header or cpp
Date 2011-07-21 11:27 -0400
Organization A noiseless patient Spider
Message-ID <j09gha$c2p$1@dont-email.me> (permalink)
References <d0a4638c-2b91-4099-8718-cb47ada19e53@h14g2000yqd.googlegroups.com>

Show all headers | View raw


On 7/21/2011 11:11 AM, Christopher wrote:
> I don't use #defines myself, or very rarely. We are in the middle of a
> style war and a coding style is being written up. Which brings the
> topic of #define in preexisting code.
>
> Obviously, #define directives the header needs will have to go in the
> header. But what of all of the #defines that are used like constants?
>
> example
> #define MYSILLYSTRING "I'm a String"
>
> When these are only used in a class' .cpp?
>
> Should these go in the .h or the .cpp file? Reasoning?

Depends.  If more than one source file uses such macros, they should 
probably stay in *one place* so when there's a need to change the value, 
you'd only go to one place to change it.  The simplest example is some 
kind of *version* designation that might be needed in both C++ and 
*resource* files.

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

#define - in header or cpp Christopher <cpisz@austin.rr.com> - 2011-07-21 08:11 -0700
  Re: #define - in header or cpp Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-21 11:27 -0400
  Re: #define - in header or cpp "Balog Pal" <pasa@lib.hu> - 2011-07-21 17:34 +0200
    Re: #define - in header or cpp Christopher <cpisz@austin.rr.com> - 2011-07-21 10:42 -0700
    Re: #define - in header or cpp Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-07-21 20:36 +0200
      Re: #define - in header or cpp Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-21 15:21 -0400
        Re: #define - in header or cpp Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-07-21 23:27 +0200
      Re: #define - in header or cpp Ian Collins <ian-news@hotmail.com> - 2011-07-22 09:35 +1200
        Re: #define - in header or cpp Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-07-21 23:57 +0200
        Re: #define - in header or cpp Thomas Boell <tboell@domain.invalid> - 2011-07-22 01:06 +0200
          Re: #define - in header or cpp Ian Collins <ian-news@hotmail.com> - 2011-07-22 11:14 +1200
          Re: #define - in header or cpp Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-07-22 08:49 +0200
            Re: #define - in header or cpp Joe Greer <jgreer@doubletake.com> - 2011-07-22 13:23 +0000
            Re: #define - in header or cpp James Kanze <james.kanze@gmail.com> - 2011-07-22 12:58 -0700
    Re: #define - in header or cpp James Kanze <james.kanze@gmail.com> - 2011-07-22 12:51 -0700
  Re: #define - in header or cpp gwowen <gwowen@gmail.com> - 2011-07-22 00:29 -0700
    Re: #define - in header or cpp Christopher <cpisz@austin.rr.com> - 2011-07-22 15:56 -0700
  Re: #define - in header or cpp Juha Nieminen <nospam@thanks.invalid> - 2011-07-22 14:33 +0000
    Re: #define - in header or cpp Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-07-26 11:26 +0000
      Re: #define - in header or cpp Juha Nieminen <nospam@thanks.invalid> - 2011-07-26 16:14 +0000

csiph-web