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


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

Re: Equates or Synonyms?

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Equates or Synonyms?
Date 2011-11-28 02:41 +0100
Organization A noiseless patient Spider
Message-ID <jauosu$efo$1@dont-email.me> (permalink)
References <MPG.293c70af3b85a5c09896d0@news.eternal-september.org>

Show all headers | View raw


On 28.11.2011 00:07, Mike Copeland wrote:
>     Is there a C/C++ language

I think you mean C++, since you're posting in a C++ group.

There is no such language as "C/C++".

C and C++ are different languages.


> capability to "equate" or use a synonym for
> an identifier?

Yes, but it depends on the kind of identifier.

E.g. `typedef` works for types.

Deriving a class works for class  types.

Function pointer works for function.

References work for v

>  I have the following declaration:
>
> struct DEF_STRUCT
> {
>      int      EPace;               // event maximum pace
>      int      TFCount;             // Total Finishers Counts
>      short    ADepth;              // Awards Depth
>      short    SFMales, SFFemales;  // Skipped Finishers
>      unsigned short dbeMales, dbeFemales;
>      unsigned short finMales, finFemales;
>      unsigned short prtMales, prtFemales;
>      float    EDist;               // event distance in miles
> [etc.]
> } ;

Don't use ALL UPPERCASE identifiers except for macros, where you should 
always use them (as a rule).

That's both to avoid readers becoming eyesore and deaf from all the 
SHOUTING, and in order to have a separate set of possible names for 
macros, which don't respect scopes.

Don't sweat it with saving some bits and bytes. The `short` elements 
here are perhaps not particularly troublesome, but the `unsigned short` 
elements are bug attractors, and the `float` is an unnecessary small 
inefficiency on modern computers.

Also, don't try so hard to save on typing.

Remember, when Ken Thompson was asked what he'd do differently if he 
were to design Unix from scratch again, he answered: "I'd spell creat 
with an e".

Saving on single characters, with names like "creat" and "hlt", is just 
dumb.

Also, use a /single convention/ for data member / variable names, like 
starting with lowercase name, or starting with uppercase, but not a 
haphazard alteration between different conventions.

So, like ...


struct ProperNameForThisTYpe
{
     int      eventMaximumPace;       // was "EPace" shortening
     int      totalFinishersCount;    // was "TFCount" shorting
     int      awardsDepth;            // was "ADepth" of type short
     int      skippedFinishersMale;   // was "SFMales" of type short
     int      skippedFinishersFemale; // was "SFemales" of type short
     int dbeMales, dbeFemales;        // what do these names mean?
     int finMales, finFemales;        // what do these names mean?
     int prtMales, prtFemales;        // what do these names mean?
     double   evenDistanceInMiles;    // was "EDist" of type float
[etc.]
} ;



> and I'd like to "reuse" some of the names (such as EPace or ADepth) with
> different identifiers.  That is, in some of my programs where I have
> this structure declared I'd like to use a different name for, say,
> EPace, because I'm not actually using that data element in that
> particular application.

Why do you want a different name when you're not using it?

The simplest solution is then to ignore the name.

After all, you're not using it.


>     Other languages such as Pascal have an "equate" statement which does
> this,

No, you're perhaps thinking of Fortran.

> and I can't find such a feature in C/C++.  Does this exist?  TIA

See above.


Cheers & hth.,

- Alf

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


Thread

Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-27 16:07 -0700
  Re: Equates or Synonyms? Ian Collins <ian-news@hotmail.com> - 2011-11-28 12:50 +1300
    Re: Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-27 21:21 -0700
  Re: Equates or Synonyms? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-11-28 02:41 +0100
    Re: Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-27 21:19 -0700
      Re: Equates or Synonyms? Ian Collins <ian-news@hotmail.com> - 2011-11-28 17:35 +1300
        Re: Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-28 16:03 -0700
          Re: Equates or Synonyms? Ian Collins <ian-news@hotmail.com> - 2011-11-29 12:52 +1300
            Re: Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-28 22:00 -0700
              Re: Equates or Synonyms? Ian Collins <ian-news@hotmail.com> - 2011-11-29 18:13 +1300
              Re: Equates or Synonyms? ralph <nt_consulting64@yahoo.net> - 2011-11-28 23:21 -0600
              Re: Equates or Synonyms? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-29 12:10 +0000
      Re: Equates or Synonyms? Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-28 01:40 -0600
      Re: Equates or Synonyms? Stuart Redmann <DerTopper@web.de> - 2011-11-28 02:38 -0800
    Re: Equates or Synonyms? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-28 13:24 +0000
  Re: Equates or Synonyms? "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-28 19:21 +0000
    Re: Equates or Synonyms? mrc2323@cox.net (Mike Copeland) - 2011-11-28 16:14 -0700
      Re: Equates or Synonyms? Kalle Olavi Niemitalo <kon@iki.fi> - 2011-11-29 09:01 +0200

csiph-web