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


Groups > comp.lang.c++ > #11871 > unrolled thread

Equates or Synonyms?

Started bymrc2323@cox.net (Mike Copeland)
First post2011-11-27 16:07 -0700
Last post2011-11-29 09:01 +0200
Articles 18 — 9 participants

Back to article view | Back to comp.lang.c++


Contents

  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

#11871 — Equates or Synonyms?

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-27 16:07 -0700
SubjectEquates or Synonyms?
Message-ID<MPG.293c70af3b85a5c09896d0@news.eternal-september.org>
   Is there a C/C++ language capability to "equate" or use a synonym for 
an identifier?  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.]
} ;

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.
   Other languages such as Pascal have an "equate" statement which does 
this, and I can't find such a feature in C/C++.  Does this exist?  TIA

[toc] | [next] | [standalone]


#11872

FromIan Collins <ian-news@hotmail.com>
Date2011-11-28 12:50 +1300
Message-ID<9jg0mkF4d0U22@mid.individual.net>
In reply to#11871
On 11/28/11 12:07 PM, Mike Copeland wrote:
>     Is there a C/C++ language capability to "equate" or use a synonym for
> an identifier?  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.]
> } ;
>
> 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.

A different name for EPace, or a different type?

If the latter, use a typedef in place of int for the type.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11876

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-27 21:21 -0700
Message-ID<MPG.293cba25f4ccb0469896d2@news.eternal-september.org>
In reply to#11872
> >     Is there a C/C++ language capability to "equate" or use a synonym for
> > an identifier?  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.]
> > } ;
> >
> > 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.
> 
> A different name for EPace, or a different type?
> 
> If the latter, use a typedef in place of int for the type.

   A different name - for personal documentation.

[toc] | [prev] | [next] | [standalone]


#11873

From"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Date2011-11-28 02:41 +0100
Message-ID<jauosu$efo$1@dont-email.me>
In reply to#11871
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

[toc] | [prev] | [next] | [standalone]


#11875

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-27 21:19 -0700
Message-ID<MPG.293cb9d8c4425bd79896d1@news.eternal-september.org>
In reply to#11873
> > capability to "equate" or use a synonym for
> > an identifier?
> 
> Yes, but it depends on the kind of identifier.
> References work for v
  ^^^^^^^^^^^^^^^^^^^^^
   I don't understand what you mean here.

> >  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.]
> > } ;
> > 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.

   I only want to use a more descriptive name for the variable in the 
application code.  I want to maintain _some_ level of useful 
documentation in my code...

[toc] | [prev] | [next] | [standalone]


#11877

FromIan Collins <ian-news@hotmail.com>
Date2011-11-28 17:35 +1300
Message-ID<9jghddF4d0U23@mid.individual.net>
In reply to#11875
On 11/28/11 05:19 PM, Mike Copeland wrote:
>>> capability to "equate" or use a synonym for
>>> an identifier?
>>
>> Yes, but it depends on the kind of identifier.
>> References work for v
>    ^^^^^^^^^^^^^^^^^^^^^
>     I don't understand what you mean here.
>
>>>   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.]
>>> } ;
>>> 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.
>
>     I only want to use a more descriptive name for the variable in the
> application code.  I want to maintain _some_ level of useful
> documentation in my code...

Then don't bother with the name of type, just give the variable a better 
name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's 
advice about mixing naming convections!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11915

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-28 16:03 -0700
Message-ID<MPG.293dc12863cb15909896d3@news.eternal-september.org>
In reply to#11877
> >>> capability to "equate" or use a synonym for
> >>> an identifier?
> >>>   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.]
> >>> } ;
> >>> 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.
> >
> >     I only want to use a more descriptive name for the variable in the
> > application code.  I want to maintain _some_ level of useful
> > documentation in my code...
> 
> Then don't bother with the name of type, just give the variable a better 
> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's 
> advice about mixing naming convections!

   That's one reason why I want this capability: I know the name isn't 
"good", but I have any applications where it's in my code but I want to 
gradually migrate to the better name.  Some of these applications are 
old and don't need updates right now, so I'd leave them alone for a 
while while I work on current stuff...

[toc] | [prev] | [next] | [standalone]


#11918

FromIan Collins <ian-news@hotmail.com>
Date2011-11-29 12:52 +1300
Message-ID<9jil6iF570U1@mid.individual.net>
In reply to#11915
On 11/29/11 12:03 PM, Mike Copeland wrote:
>>>>> capability to "equate" or use a synonym for
>>>>> an identifier?
>>>>>    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.]
>>>>> } ;
>>>>> 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.
>>>
>>>      I only want to use a more descriptive name for the variable in the
>>> application code.  I want to maintain _some_ level of useful
>>> documentation in my code...
>>
>> Then don't bother with the name of type, just give the variable a better
>> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's
>> advice about mixing naming convections!
>
>     That's one reason why I want this capability: I know the name isn't
> "good", but I have any applications where it's in my code but I want to
> gradually migrate to the better name.  Some of these applications are
> old and don't need updates right now, so I'd leave them alone for a
> while while I work on current stuff...

Being somewhat lazy these days, I'd just load up the projects in my 
current IDE and select refactor->rename.  Job done.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11927

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-28 22:00 -0700
Message-ID<MPG.293e14c4c13b6249896d5@news.eternal-september.org>
In reply to#11918
In article <9jil6iF570U1@mid.individual.net>, ian-news@hotmail.com 
says...
> >>>> 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.
> >>>
> >>>      I only want to use a more descriptive name for the variable in the
> >>> application code.  I want to maintain _some_ level of useful
> >>> documentation in my code...
> >>
> >> Then don't bother with the name of type, just give the variable a better
> >> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's
> >> advice about mixing naming convections!
> >
> >     That's one reason why I want this capability: I know the name isn't
> > "good", but I have any applications where it's in my code but I want to
> > gradually migrate to the better name.  Some of these applications are
> > old and don't need updates right now, so I'd leave them alone for a
> > while while I work on current stuff...
> 
> Being somewhat lazy these days, I'd just load up the projects in my 
> current IDE and select refactor->rename.  Job done.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Huh?  What is this?  I've never seen or heard of any such "IDE 
capability" (of course, I use VS6.0, which everyone constantly tells me 
it sucks...).  <sigh...>

[toc] | [prev] | [next] | [standalone]


#11928

FromIan Collins <ian-news@hotmail.com>
Date2011-11-29 18:13 +1300
Message-ID<9jj809F4d0U30@mid.individual.net>
In reply to#11927
On 11/29/11 06:00 PM, Mike Copeland wrote:
> In article<9jil6iF570U1@mid.individual.net>, ian-news@hotmail.com
> says...
>>>>>> 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.
>>>>>
>>>>>       I only want to use a more descriptive name for the variable in the
>>>>> application code.  I want to maintain _some_ level of useful
>>>>> documentation in my code...
>>>>
>>>> Then don't bother with the name of type, just give the variable a better
>>>> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's
>>>> advice about mixing naming convections!
>>>
>>>      That's one reason why I want this capability: I know the name isn't
>>> "good", but I have any applications where it's in my code but I want to
>>> gradually migrate to the better name.  Some of these applications are
>>> old and don't need updates right now, so I'd leave them alone for a
>>> while while I work on current stuff...
>>
>> Being somewhat lazy these days, I'd just load up the projects in my
>> current IDE and select refactor->rename.  Job done.
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     Huh?  What is this?  I've never seen or heard of any such "IDE
> capability" (of course, I use VS6.0, which everyone constantly tells me
> it sucks...).<sigh...>


It's a feature of NetBeans and I assume Eclipse as well.

All copes of VS6.0 should have self destructed many, many years ago!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#11929

Fromralph <nt_consulting64@yahoo.net>
Date2011-11-28 23:21 -0600
Message-ID<hkq8d7154un7mdfqo9ecadkms2n8uu7eat@4ax.com>
In reply to#11927
On Mon, 28 Nov 2011 22:00:06 -0700, mrc2323@cox.net (Mike Copeland)
wrote:

>In article <9jil6iF570U1@mid.individual.net>, ian-news@hotmail.com 
>says...
>> >>>> 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.
>> >>>
>> >>>      I only want to use a more descriptive name for the variable in the
>> >>> application code.  I want to maintain _some_ level of useful
>> >>> documentation in my code...
>> >>
>> >> Then don't bother with the name of type, just give the variable a better
>> >> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's
>> >> advice about mixing naming convections!
>> >
>> >     That's one reason why I want this capability: I know the name isn't
>> > "good", but I have any applications where it's in my code but I want to
>> > gradually migrate to the better name.  Some of these applications are
>> > old and don't need updates right now, so I'd leave them alone for a
>> > while while I work on current stuff...
>> 
>> Being somewhat lazy these days, I'd just load up the projects in my 
>> current IDE and select refactor->rename.  Job done.
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   Huh?  What is this?  I've never seen or heard of any such "IDE 
>capability" (of course, I use VS6.0, which everyone constantly tells me 
>it sucks...).  <sigh...>

Visual Studio, out-of-the-box, only supports the Refactor! option for
VB.Net and C#. However, Microsoft offers a Refactor Plug-In for VC++
you can download at ...
http://msdn.microsoft.com/en-us/vstudio/bb737896

Worth a look. 

-ralph

[toc] | [prev] | [next] | [standalone]


#11952

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-11-29 12:10 +0000
Message-ID<slrnjd9iu8.1bk.grahn+nntp@frailea.sa.invalid>
In reply to#11927
On Tue, 2011-11-29, Mike Copeland wrote:
> In article <9jil6iF570U1@mid.individual.net>, ian-news@hotmail.com 
> says...
>> >>>> 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.
>> >>>
>> >>>      I only want to use a more descriptive name for the variable in the
>> >>> application code.  I want to maintain _some_ level of useful
>> >>> documentation in my code...
>> >>
>> >> Then don't bother with the name of type, just give the variable a better
>> >> name.  Try "eventMaximumPace" rather than "EPace".  Also heed Alf's
>> >> advice about mixing naming convections!
>> >
>> >     That's one reason why I want this capability: I know the name isn't
>> > "good", but I have any applications where it's in my code but I want to
>> > gradually migrate to the better name.  Some of these applications are
>> > old and don't need updates right now, so I'd leave them alone for a
>> > while while I work on current stuff...
>> 
>> Being somewhat lazy these days, I'd just load up the projects in my 
>> current IDE and select refactor->rename.  Job done.
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    Huh?  What is this?  I've never seen or heard of any such "IDE 
> capability" (of course, I use VS6.0, which everyone constantly tells me 
> it sucks...).  <sigh...>

In cases like this, it doesn't matter that your IDE sucks. If you
rename the definition of the struct member, the compiler will check
that you've renamed the uses correctly.  A Perl one-liner or similar
can do the actual renaming.

The rest is a matter of management, e.g. being allowed to make trivial
changes to a stable application, being allowed to argue that these
changes are safe without a month of testing, and being able to postpone
delivery to users until some vital (to the users) change comes along.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#11880

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-11-28 01:40 -0600
Message-ID<Xns9FAB627341865myfirstnameosapriee@216.196.109.131>
In reply to#11875
mrc2323@cox.net (Mike Copeland) wrote in
news:MPG.293cb9d8c4425bd79896d1@news.eternal-september.org: 

>> > capability to "equate" or use a synonym for
>> > an identifier?
>> 
>> Yes, but it depends on the kind of identifier.
>> References work for v
>   ^^^^^^^^^^^^^^^^^^^^^
>    I don't understand what you mean here.
> 
>> >  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.]
>> > } ;
>> > 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.
> 
>    I only want to use a more descriptive name for the variable in the 
> application code.  I want to maintain _some_ level of useful 
> documentation in my code...

If your variable is otherwise same in two programs, but has different 
names, it can only cause confusion. 

If the variable is different, e.g. serves for different purposes, then the 
whole struct should have another name as well. This might be best achieved 
by putting the invariant part of the data in a base class/struct and derive 
different specific structs from that in respective applications:

struct def_base
{
    int      TFCount;             // Total Finishers Counts 
    short    SFMales, SFFemales;  // Skipped Finishers
    unsigned short dbeMales, dbeFemales;
    unsigned short finMales, finFemales;
    unsigned short prtMales, prtFemales;
    float    EDist;               // event distance in miles 
[etc.]
} ;

// app A
struct first_def_struct: public def_base {
    int      EPace;               // event maximum pace 
};

// app B
struct another_def_struct: public def_base {
    double    EspeedOrWhatever;
};

Such derivation (without any 'virtual' keyword around) is a compile-time-
only concept, so it won't cause any overhead at the run-time (in the worst 
case the struct size might become a bit larger because of alignment rules, 
but this is also nothing to worry about unless you have many millions of 
those structs). 

hth
Paavo

[toc] | [prev] | [next] | [standalone]


#11883

FromStuart Redmann <DerTopper@web.de>
Date2011-11-28 02:38 -0800
Message-ID<b3e0b2f6-e058-43eb-b51b-ec238e03f05d@n35g2000yqf.googlegroups.com>
In reply to#11875
Mike Copeland wrote:
> > > capability to "equate" or use a synonym for
> > > an identifier?

Alf P. Steinbach wrote:
> > Yes, but it depends on the kind of identifier.
> > References work for v

On 28 Nov., Mike Copeland wrote:
>   ^^^^^^^^^^^^^^^^^^^^^
>    I don't understand what you mean here.

He means something like this:
struct DEF_STRUCT
{
  int EPace;
  int& ABetterNameForEPace;
  /* snip */

  // This constructor for DEF_STRUCT binds
  // ABetterNameForEPace to EPace.
  DEF_STRUCT ()
    : ABetterNameForEPace (EPace)
  {}
};

Then you can do:

DEF_STRUCT s;
s.EPace = 5;
std::cout << s.ABetterNameForEPace << std::endl;
s.EPace = 7;
std::cout << s.ABetterNameForEPace << std::endl;

and you'll get the output
5
7

Note that introducing references may alter the binary layout of your
struct. Most probably the reference will be implemented through an
additional pointer.

There is a non-portable compiler extension for Microsoft Visual C++
which lets you achieve the same thing but without any changes to the
binary layout. Google for __declspec property.

However, the simplest would be to just add a setter and getter method
to the struct:
struct DEF_STRUCT
{
  int EPace;
  int getABetterNameForEPace ()
  {
    return EPace;
  }
  void setABetterNameForEPace (int NewValue)
  {
    EPace = NewValue;
  }
  /* snip */
};

Regards,
Stuart

PS: Please keep the names of the people you are quoting from. Better
yet, keep a complete history of the talk (at least the part that you
are refering to). Not everybody has access to all postings of this
group.

[toc] | [prev] | [next] | [standalone]


#11888

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-11-28 13:24 +0000
Message-ID<slrnjd72t0.1bk.grahn+nntp@frailea.sa.invalid>
In reply to#11873
On Mon, 2011-11-28, Alf P. Steinbach wrote:
> On 28.11.2011 00:07, Mike Copeland wrote:
...
>> 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.]
>> } ;
...

> 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".

(But I bet he wouldn't have called it createFile.)

Anyway, I think the struct above shows something else: an awkward name
is often a sign of deeper awkwardness.  There's room for at least one
struct type here, with  a "males" and a "females" instance.
That way you can say 'foo.males.finish' or whatever -- and documentation
becomes easier.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#11902

From"Paul" <pchrist<nospam>or@yahoo.co.uk>
Date2011-11-28 19:21 +0000
Message-ID<jb0mv6$2jgk$1@adenine.netfront.net>
In reply to#11871
"Mike Copeland" <mrc2323@cox.net> wrote in message 
news:MPG.293c70af3b85a5c09896d0@news.eternal-september.org...
>   Is there a C/C++ language capability to "equate" or use a synonym for
> an identifier?  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.]
> } ;
>
> 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.
>   Other languages such as Pascal have an "equate" statement which does
> this, and I can't find such a feature in C/C++.  Does this exist?  TIA

All instances of this struct will have the same members.
The data members cannot have a different names across different instances, 
all instances have the same names.


You could have 2 different structs with the same name in different 
namespaces, i.e:

namespace A{
struct def_struct{
 int dataNameA;
};
}

namespace B{
struct def_struct{
 int dataNameB;
};
}

Then you just use using namespaceX for whatever one you want to use. Or you 
could play around using namespaces in different ways, but its not clear 
exactly what you are trying to do. References to data members may be another 
option, again dependant on what you're trying to do.


HTH
Paul.





--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

[toc] | [prev] | [next] | [standalone]


#11916

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-28 16:14 -0700
Message-ID<MPG.293dc3aee2c25e099896d4@news.eternal-september.org>
In reply to#11902
> >   Is there a C/C++ language capability to "equate" or use a synonym for
> > an identifier?  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.]
> > } ;
> >
> > 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.
> >   Other languages such as Pascal have an "equate" statement which does
> > this, and I can't find such a feature in C/C++.  Does this exist?  TIA
> 
> All instances of this struct will have the same members.
> The data members cannot have a different names across different instances, 
> all instances have the same names.
> 
> You could have 2 different structs with the same name in different 
> namespaces, i.e:
> 
> namespace A{
> struct def_struct{
>  int dataNameA;
> };
> }
> 
> namespace B{
> struct def_struct{
>  int dataNameB;
> };
> }
> 
> Then you just use using namespaceX for whatever one you want to use. Or you 
> could play around using namespaces in different ways, but its not clear 
> exactly what you are trying to do. References to data members may be another 

   That's not possible for my applications.  The structure and object 
are defined and declared in common library files, and there are many 
applications that use them asis.  The common library files establish and 
populate this structure object, but in some newer applications I want to 
use some of the data fields in other ways that they're more commonly 
used.  I know that the integrity of the data won't be compromised by 
this reuse, because it's discrete within this application - the data 
doesn't extend beyond it.
   Thus, I want the structure object to be initialized (by common 
processing), but I want to manipulate some of the data fields (with 
better names) uniquely in some new programs.  Specifically, I want to 
use some of the "int" variables as counters for special application(s), 
knowing that their normal usage isn't being applied in the new program
(s).  Hence, I'd like to use better, more descriptive names there...

[toc] | [prev] | [next] | [standalone]


#11932

FromKalle Olavi Niemitalo <kon@iki.fi>
Date2011-11-29 09:01 +0200
Message-ID<87r50rza2k.fsf@Niukka.kon.iki.fi>
In reply to#11916
mrc2323@cox.net (Mike Copeland) writes:

>    Thus, I want the structure object to be initialized (by common 
> processing), but I want to manipulate some of the data fields (with 
> better names) uniquely in some new programs.  Specifically, I want to 
> use some of the "int" variables as counters for special application(s), 
> knowing that their normal usage isn't being applied in the new program
> (s).  Hence, I'd like to use better, more descriptive names there...

Could you use anonymous unions for that?

struct DEF_STRUCT
{
    union
    {
        int      EPace;               // event maximum pace 
        int      CounterForSpecialApplication;
    };
    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.]
} ;

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web