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


Groups > comp.lang.c > #74373

Re: CAlive special use instance class, called an angel

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: CAlive special use instance class, called an angel
Date 2015-10-31 11:03 +1300
Message-ID <d9i7p4F2lrhU7@mid.individual.net> (permalink)
References (1 earlier) <d9fvboF2lrhU5@mid.individual.net> <306c76e3-1ac6-4237-af32-bd5ef4488dd0@googlegroups.com> <MPG.309ca0078690a92d5b@news.eternal-september.org> <77be262f-6ad6-4b73-bad7-e28d42fbc12a@googlegroups.com> <06012d90-75a1-49ae-80da-fb3959d5a842@googlegroups.com>

Show all headers | View raw


Rick C. Hodgin wrote:
> On Friday, October 30, 2015 at 1:53:55 AM UTC-4, Malcolm McLean wrote:

>
> I am in no way a C++ expert.  I could be wrong in my understanding
> of how things operate in C++.  I probably am wrong.
>
> In my use of angels, I am creating a specific thing which can be
> encapsulated behind its instance use name, giving it readable context
> and meaning in source code.
>
> The same angel could be used for different contexts.  If you created
> an angel to assemble a message to be passed, for example, then it
> might have a meaning when adding a warning to a computed value, or
> an error, or maybe it's just a note attached for the user to read
> indicating the size of the thing that was loaded, or how many seconds
> it took to process, etc.
>
> In each of these cases the angel instance names could be given as
> warning, error, note, time, etc., and then when used it would convey
> in code what the purpose of the instance use was.

Which as others have shown can be done in C with a typedef and in in C++ 
with a typedef or "using".

> -----
> With regards to C++:
>
> In my testing using MSVC and g++, when this is used the created
> instances of CWhatever in the calling function never have their
> destructor called unless they are explicitly deleted, which means
> variable name management.

Off topic I know, but it is the weekend...

In C++ the destructor is called when the object goes out of scope, which 
appears to be what you wanted.

> The only cases I tested which do explicitly call their destructor
> are here:
>
>      CWhatever c1("c1"), c2("c2"), c3("c3");
>      whatever(&c1, &c2, &c3);
>
> But those destructors were not called until the function exited, and
> remained in scope from the point of their creation until the function
> exited.
>
>> Buy would wouldn't normally write a C++, as opposed to C, function
>> like that. If "something" doesn't modify the arguments, which,
>> since we're ignoring them after the call, is a reasonable guess,
>> normally it would be written,
>>
>> void something(CWhatever const &w1, CWhatever const &w2, CWhatever const &w3).
>>
>> We can now create the arguments as we call, but not using a name,
>> it needs to be
>>
>> something( CWhatever("1"), CWhatever("2"), CWhatever("3"))
>
> In my testing, this creates const instances of CWhatever which also
> required changes to the definition of some class member functions
> to make them suitable for const access.  This changes the nature of
> what can be done within the class.

That is correct.  The temporary parameter objects scope is the function 
call. They will not exist after the call son there is no point in trying 
to modify them.

> And if you alter the behavior into something like this:
>
>      something( &CWhatever("1"), &CWhatever("2"), &CWhatever("3"));
>
> You need to use -fpermissive in g++ to access the address of the
> "temporary" variable it creates, and you actually need to use
> this form because the "1", "2", and "3" are interpreted as const
> char* by default:

They (as string literals) are const char* by the language definition.

>      something( &CWhatever((char*)"1"),
>                 &CWhatever((char*)"2"),
>                 &CWhatever((char*)"3")  );
>
> You could wrap it in this:
>
>      #define w(a) &CWhatever((char*)a)
>      something(w("1"), w("2"), w("3"));
>
> Now you have the same functionality as an angel.

The same broken functionality.  It might help you to understand the rule 
by considering a change in parameter type:

void something( int const &w1 );

something( 42 );

Now would it make sense to be able to modify w1?

> But perhaps that is my own misunderstanding of C++ and there is
> another way to get the functionality using const.
>
>> this is also comparatively unusual, because normally "something"
>> would just take "1", "2", "3", that's all the actual information
>> we're passing it, but it's a snippet example.
>>
>> I don't really see what programming issue angels solve, however.
>> If "something" is polymorphic we can presumably set the type
>> where the angel is defined, rather than where it is instantiated.
>> But I can't really think of a use case for that.
>
> Everything about CAlive ties back to RDC (Rapid Development Compiler).
>
> In all of the cases I have shown, the conveyance of everything in
> source code is to make the code clearer, easier to understand, to
> self-document and connect things which are naturally connected
> logically by their innate form, and all in a syntax which seems
> much clearer and easier (once you get past the learning curve and
> understand it and become familiar with it, and remember that it
> will be shown in a GUI editor) than the equivalent code in C++
> (when there is equivalent C++ code).
>

That's all well and good, but don't loose sight of the common sense 
rules other languages impose.  Most are there for a reason which you may 
not spot until you try and go in a different direction.

I guess what I'm saying is learn from those who have trodden the same 
path before you.

-- 
Ian Collins

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


Thread

CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 18:18 -0700
  Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 18:23 -0700
  Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-30 14:27 +1300
    Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 19:18 -0700
      Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-10-29 22:29 -0700
        Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-29 22:53 -0700
          Re: CAlive special use instance class, called an angel gazelle@shell.xmission.com (Kenny McCormack) - 2015-10-30 08:40 +0000
            Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-30 01:49 -0700
              Re: CAlive special use instance class, called an angel Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 09:15 +0000
              Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:37 -0700
                Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:25 +0100
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:35 -0700
                Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:34 +0100
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:44 -0700
                Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 13:32 +0000
          Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:34 -0700
            Re: CAlive special use instance class, called an angel gazelle@shell.xmission.com (Kenny McCormack) - 2015-10-30 13:13 +0000
              Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:25 -0700
            Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 11:03 +1300
              Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 15:17 -0700
                Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 16:55 +1300
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:13 -0700
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:36 -0700
                Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 17:44 +1300
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:53 -0700
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:57 -0700
                Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 22:16 +1300
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 09:50 -0700
                Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 01:52 -0700
              Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 22:44 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 16:14 -0700
                Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 01:03 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 19:14 -0700
                Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 11:56 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 09:55 -0700
                Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 20:17 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 14:27 -0700
                Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 22:38 +0000
                Re: CAlive special use instance class, called an angel Richard Damon <Richard@Damon-Family.org> - 2015-10-31 10:44 -0400
                Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 12:16 -0700
                Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 13:13 +1300
                Re: CAlive special use instance class, called an angel James Kuyper <jameskuyper@verizon.net> - 2015-10-30 22:17 -0400
                Re: CAlive special use instance class, called an angel James Kuyper <jameskuyper@verizon.net> - 2015-10-30 22:31 -0400
        Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-10-30 01:42 -0700
      Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 09:38 +0000
        Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 04:35 -0700
          Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:10 +0100
            Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:21 -0700
              Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:43 +0100
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:55 -0700
                Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 11:09 +1300
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 15:19 -0700
                Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 00:47 +0100
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 17:24 -0700
                Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 23:39 +0100
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 16:50 -0800
                Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-11-01 23:22 -0800
                Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-11-02 13:54 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 06:23 -0800
                Re: CAlive special use instance class, called an angel supercat@casperkitty.com - 2015-11-01 18:46 -0800
            Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-10-30 13:55 +0000
  Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 10:16 +0100
    Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:39 -0700
      Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:38 +0100
        Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:59 -0700
          Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-10-30 14:41 +0000
            Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:31 -0700
            Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:38 -0700
            Re: CAlive special use instance class, called an angel asetofsymbols@gmail.com - 2015-10-30 08:39 -0700
              Re: CAlive special use instance class, called an angel supercat@casperkitty.com - 2015-10-30 15:20 -0700
          Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:48 +0100
            Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 09:07 -0700
              Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 14:53 +0100
                Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 06:12 -0800
                Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-11-02 14:16 +0000
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 06:25 -0800
                CLC as a dating site (Was: CAlive special use instance class, called an angel) gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 14:33 +0000
                Re: CLC as a dating site (Was: CAlive special use instance class, called an angel) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 06:45 -0800
                Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 07:53 -0800
                Using CLC for crowdsourcing (Was: CAlive special use instance class, called an angel) gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 15:56 +0000

csiph-web