Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| 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 16:55 +1300 |
| Message-ID | <d9isclF2lriU1@mid.individual.net> (permalink) |
| References | (3 earlier) <MPG.309ca0078690a92d5b@news.eternal-september.org> <77be262f-6ad6-4b73-bad7-e28d42fbc12a@googlegroups.com> <06012d90-75a1-49ae-80da-fb3959d5a842@googlegroups.com> <d9i7p4F2lrhU7@mid.individual.net> <74befcf7-7d6b-4cc8-bbfa-763646745ce6@googlegroups.com> |
Rick C. Hodgin wrote:
> On Friday, October 30, 2015 at 6:03:33 PM UTC-4, Ian Collins wrote:
>> 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".
>
> While C and C++ allow for alternatives, I don't want to use a typedef
> or a using. It's unnecessary clutter.
Then you had better make sure that your syntax is unambiguous or you
will end up with yet more confusion.
>>> -----
>>> 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 angels go out of scope after the expression they're used in. I
> see that Malcom's C++ const example does that:
>
> void something(CWhatever const &w1, CWhatever const &w2, CWhatever const &w3)
>
> ...but in my testing, it required changes to the way the accessor had
> to be written. That may be a weakness in my understanding C++ syntax,
> however, though I currently believe it to be because they are declared
> const.
That's correct. As I've said elsewhere it makes limited sense to pass a
mutable copy of something that is about to be destroyed.
>>> 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.
>
> That is the behavior of angels, but without const or & requirements, as
> all angels are passed as pointers.
So what happens if a function assigned one of these pointers to a global
variable?
>>> 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?
>
> That's my point... why would you want to use const &?
For the same reasons you would use const *: that you do not want to or
are unable to modify the referenced object.
> It makes no
> sense. The purpose of angels is to do real things classes can do,
> but to only have their limited lifespan, and to provide name reuse
> without separate instances being manually accounted for.
Which is what has been demonstrated with basic C++ classes.
> In my testing, I could not find a form like Malcom's const & form
> that also called the destructor immediately after creation while
> using a pointer. If there is one, angels add no value there. If
> there isn't one, then that's one of two things angels add for value.
That's correct because to do so would be unsafe.
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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