Wednesday, April 13, 2016

Digest for comp.lang.c++@googlegroups.com - 25 updates in 3 topics

"Tuấn Trần" <trananhtuan260493@gmail.com>: Apr 12 09:46PM -0700

Hi,
I face a declaration function in C++ BUT I don't know what's this mean!
This is my code:
bool Check() const;
 
Can you explain this for me?
Thanks!
Wouter van Ooijen <wouter@voti.nl>: Apr 13 07:34AM +0200

Op 13-Apr-16 om 6:46 AM schreef Tuấn Trần:
> bool Check() const;
 
> Can you explain this for me?
> Thanks!
 
If you want to program in C++ and you don't understand what a function
declaration is or means than my conclusion is that you should read an
(introductory) book on C++ or even C.
 
If you con't know what a specific part of that declaration (for instance
the 'const') means you should ask a more specific question.
 
Wouter van Ooijen
"Tuấn Trần" <trananhtuan260493@gmail.com>: Apr 13 01:31AM -0700

Vào 12:35:02 UTC+7 Thứ Tư, ngày 13 tháng 4 năm 2016, Wouter van Ooijen đã viết:
 
> If you con't know what a specific part of that declaration (for instance
> the 'const') means you should ask a more specific question.
 
> Wouter van Ooijen
 
Hi,
Yes, I don't know what 'const' mean in declaration!
Can you explain this for me?
Robert Wessel <robertwessel2@yahoo.com>: Apr 13 03:51AM -0500

On Tue, 12 Apr 2016 21:46:32 -0700 (PDT), Tu?n Tr?n
>This is my code:
>bool Check() const;
 
>Can you explain this for me?
 
 
Assuming that's a member function, it declares a const member
function, which cannot alter any non-static or non-mutable data
members in the class. It allows the (const) member function to be
called on a const instance of the class (since the const member
function cannot modify - with the exceptions noted above - the class).
 
This is a C++11 feature.
Juha Nieminen <nospam@thanks.invalid>: Apr 13 10:20AM

> called on a const instance of the class (since the const member
> function cannot modify - with the exceptions noted above - the class).
 
> This is a C++11 feature.
 
What do you mean it's a C++11 feature?
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Paavo Helde <myfirstname@osa.pri.ee>: Apr 13 03:19PM +0300

On 13.04.2016 11:51, Robert Wessel wrote:
> called on a const instance of the class (since the const member
> function cannot modify - with the exceptions noted above - the class).
 
> This is a C++11 feature.
 
According to
https://www.usenix.org/legacy/publications/compsystems/1989/sum_stroustrup.pdf
, const member functions were defined and implemented in August 1985.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 13 03:32PM +0300

On 13.04.2016 15:19, Paavo Helde wrote:
> According to
> https://www.usenix.org/legacy/publications/compsystems/1989/sum_stroustrup.pdf
> , const member functions were defined and implemented in August 1985.
 
Oops sorry, more careful reading says it was later than August 1985,
sometime in 1985-1989.
"Öö Tiib" <ootiib@hot.ee>: Apr 13 08:57AM -0700

> members in the class. It allows the (const) member function to be
> called on a const instance of the class (since the const member
> function cannot modify - with the exceptions noted above - the class).
 
What do you mean by "cannot modify the class"?
Daniel <danielaparker@gmail.com>: Apr 13 09:13AM -0700


> it declares a const member function, which cannot alter ... non-mutable
> data members in the class.
 
Presumably all member functions, const or otherwise, can't alter non-mutable
data members, to the extent that that non-mutability can be expressed in the
class member definition.
 
More generally, the caller of a const member function has no guarantee that
the call won't mutate data that can reasonably be thought of as belonging
to the object, in some cases even without the use of const_cast.
 
There are no circumstances in which const can be equated with pure, so
it provides no help to the compiler and limited help to the programmer
attempting to reason about his code.
 
Daniel
David Brown <david.brown@hesbynett.no>: Apr 13 08:43PM +0200

On 13/04/16 18:13, Daniel wrote:
 
> Presumably all member functions, const or otherwise, can't alter non-mutable
> data members, to the extent that that non-mutability can be expressed in the
> class member definition.
 
"mutable" is a type qualifier that can apply to members of a class. It
means that the member in question /can/ be modified by a "const" member
function. Members that are not declared as mutable cannot be modified
by a const member function (you can cheat, using const_cast or similar
methods, but the results are undefined - and the compiler can optimise
on the assumption that you don't cheat).
 
 
> More generally, the caller of a const member function has no guarantee that
> the call won't mutate data that can reasonably be thought of as belonging
> to the object, in some cases even without the use of const_cast.
 
That is correct - as long as you qualify such "private" data as
"mutable". The caller of a const member function does have a guarantee
that data, even if it is private to the object, will not be modified
unless it is mutable.
 
 
> There are no circumstances in which const can be equated with pure, so
> it provides no help to the compiler and limited help to the programmer
> attempting to reason about his code.
 
const is not the same as "pure", and does not offer quite as many
optimisation opportunities as one might think, but it helps programmers
reason about their code and spot mistakes (by making some kinds of
errors into compile-time errors, and by documenting functionality of the
code), and it provides a number of optimisation chances to the compiler.
Daniel <danielaparker@gmail.com>: Apr 13 12:44PM -0700

On Wednesday, April 13, 2016 at 2:43:18 PM UTC-4, David Brown wrote:
 
> "mutable" is a type qualifier that can apply to members of a class.
> It means that the member in question /can/ be modified by a "const"
> member function.
 
Missed that, I was interpreting "non-mutable" in it's literal sense.
 
> Members that are not declared as mutable cannot be modified
> by a const member function [without cheating]
 
Not entirely, e.g.
 
class A
{
int* x;
 
...
 
void f() const
{
x[0] = 1;
}
};
 
> reason about their code and spot mistakes (by making some kinds of
> errors into compile-time errors, and by documenting functionality of the
> code), and it provides a number of optimisation chances to the compiler.
 
const is a hack in a language full of them, I don't think we will see it
copied in more modern languages.
 
Daniel
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 13 03:50PM -0400

On 4/13/2016 3:44 PM, Daniel wrote:
> x[0] = 1;
> }
> };
 
There is no modification of a *member* here. So, yes, *entirely*.
 
V
--
I do not respond to top-posted replies, please don't ask
Daniel <danielaparker@gmail.com>: Apr 13 01:01PM -0700

On Wednesday, April 13, 2016 at 3:51:14 PM UTC-4, Victor Bazarov wrote:
> > }
> > };
 
> There is no modification of a *member* here. So, yes, *entirely*.
 
From the user's point of view, the function is mutating data that is owned
by the object.
 
Daniel
woodbrian77@gmail.com: Apr 12 07:59PM -0700

I'd like to start a C++ meeting in the St. Paul, Minnesota area.
By the grace of G-d, I'm able to provide a meeting area in a
conference room in the office building where Ebenezer Enterprises
is, and I would be happy to give a talk or two. If you are
interested in this, please let me know.
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
Juha Nieminen <nospam@thanks.invalid>: Apr 13 06:08AM

> conference room in the office building where Ebenezer Enterprises
> is, and I would be happy to give a talk or two. If you are
> interested in this, please let me know.
 
I don't think anybody will be interested in your proselytizing.
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
David Brown <david.brown@hesbynett.no>: Apr 13 09:26AM +0200

> conference room in the office building where Ebenezer Enterprises
> is, and I would be happy to give a talk or two. If you are
> interested in this, please let me know.
 
Surely booking a conference room in your office building is standard
procedure and part of the services offered by the building management -
and it is provided by the grace of an email and a small booking fee,
rather than requiring divine intervention?
 
Or was your plan to make sure that only religious fanatics come to the
meeting?
 
Your religious beliefs are your own business - don't try to press them
onto others.
woodbrian77@gmail.com: Apr 13 09:00AM -0700

On Wednesday, April 13, 2016 at 2:26:25 AM UTC-5, David Brown wrote:
> procedure and part of the services offered by the building management -
> and it is provided by the grace of an email and a small booking fee,
> rather than requiring divine intervention?
 
G-d gives me the strength and ability to make a living.
 
 
> Or was your plan to make sure that only religious fanatics come to the
> meeting?
 
I welcome anyone that is interested.
 
Brian
Ebenezer Enterprises - "For two whole years Paul stayed there
in his own rented house and welcomed all who came to see him." Acts 28:30
 
http://webEbenezer.net
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 13 06:56PM +0100


> Brian
> Ebenezer Enterprises - "For two whole years Paul stayed there
> in his own rented house and welcomed all who came to see him." Acts 28:30
 
Brian, initially I thought you might have been a follower of Judaism
however as you are quoting a book from the New Testament it might
interest you to know, Christian, that as we know evolution is a fact we
know that Jesus Christ never existed which is a good thing too because
if he did exist he would be the biggest cunt in the universe.
 
/Flibble
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Apr 13 09:25PM +0200

On 13.04.2016 19:56, Mr Flibble wrote:
> we know evolution is a fact we
> know that Jesus Christ never existed which is a good thing too because
> if he did exist he would be the biggest cunt in the universe.
 
Now now.
 
- Alf
Daniel <danielaparker@gmail.com>: Apr 13 12:56PM -0700

On Wednesday, April 13, 2016 at 1:56:43 PM UTC-4, Mr Flibble wrote:
 
A.
 
> as we know evolution is a fact we know that Jesus Christ never existed
 
B.

> if he did exist he would be the biggest cunt in the universe.
 
If I recall my logic classes correctly, B is true if A is true (any
inference can be made from a false postulate.)
 
The difficulty is A.
 
Daniel
woodbrian77@gmail.com: Apr 13 12:56PM -0700

On Wednesday, April 13, 2016 at 12:56:43 PM UTC-5, Mr Flibble wrote:
 
> Brian, initially I thought you might have been a follower of Judaism
 
Hi, Leigh. I'm not the greatest apologist. I hope you
will leave off with the bad words.
Robbie Hatley <see.my.sig@for.my.address>: Apr 12 05:23PM -0700

On 4/12/2016 1:14 PM, Paavo Helde wrote:
 
> No, it does not (fail reliably). Try with some other compiler and you will see.
> The proper wording would be "appears to fail in quite predictably way with my
> compiler version and with my compiler options".
 
The stated result (computer just says "Abort called" and ends program) depends
on these exact inputs:
 
Text: "randip.c"
Pattern: "and"
Replacement: "or"
 
Change anything just slightly, and it either doesn't fail, or fails in a very
different way (such as, instead of saying "abort called", says "segmentation
fault, core dumped", or says "internal error: TP_NUM_C_BUFS too low: 50",
or suddenly spews 500 pages of complete gibberish; I've seen this program
do all of those the last few days).
 
> Welcome to the wonderful world of C and C++ Undefined Behavior!
 
Sort of like going on a bad drug trip. :-/
 
I think the reason the results of stack corruption is so unpredictable
and varied is, when you over-write the stack, the results depend on exactly
*what* gets clobbered. Clobber the wrong thing, and instead of saying something
relatively sane like "segmentation fault", the computer suddenly spews
a bunch of directory listings, or spews the contents of random C++ source files.
(It did both of those, yesterday.) I suppose stack corruption could even
cause worse things (over-writing disk files, damaging hardware, etc).
 
Which is why I don't use C for complex programs. Too dangerous. I'll leave
that to people more skilled than me.
 
C++ is better in that regard, what with std::vector<int> instead of
 
int sprat[50] = {0};
...857 lines of code here...
int LoopLimit = 87;
for ( int i = 0 ; i < LoopLimit ; ++i )
{
sprat[i] = SomeDamnFunc(Input[i]);
}
(Ooops! We just corrupted 4*37 bytes of the stack!)
 
Yes, I've seen professional programmers at work make *exactly* that
blunder, almost verbatim. C makes shooting one's self in the foot
in that way easy. I convinced the guys to convert to C++ and use
std::vector, std::map, std::list instead of arrays. Got rid of
a lot of bugs that way. (That was back in 2001-2006 when I was
actually heavily involved in doing C++ programming for a living.
But I digress.)
 
But Perl is even better in that regard. :D Even harder to screw things up.
 
However, I'm trying to stay proficient in all 3 of those languages
(while also learning Python as well), so that involves practice with
things which are less "safe", such as fixed-length arrays on the stack,
dynamic allocation with malloc & free, etc, in addition to the the safer
approaches of C++. Which is part of why I do certain things the old-fashioned
way in the C version of my Substitute() function. Playing with fire and
trying not to get burned.
 
 
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
woodbrian77@gmail.com: Apr 12 07:35PM -0700

On Tuesday, April 12, 2016 at 7:23:24 PM UTC-5, Robbie Hatley wrote:
 
Robbie, please don't swear here.
 
 
Brian
Ebenezer Enterprises - Making programming fun again.
http://webEbenezer.net
Daniel <danielaparker@gmail.com>: Apr 12 08:04PM -0700

> On Tuesday, April 12, 2016 at 7:23:24 PM UTC-5, Robbie Hatley wrote:
 
> Robbie, please don't swear here.
 
Brian's right, in the context of Robbie's post, it's inappropriate to have "Damn" as part of the function name.
 
It should be used in the name of the loop limit variable
 
int SomeDamnLoopLimit = 87;
 
as it's this that causes the annoyance and surprise.
 
Best regards,
Daniel
Rosario19 <Ros@invalid.invalid>: Apr 13 07:13AM +0200

On Mon, 11 Apr 2016 21:45:01 +0300, Paavo Helde wrote:
 
>whenever possible. And I am still pretty sure the actual bug was in some
>of those deleted 343 lines (and deleting them was a good way to get rid
>of the bug!)
 
i'm different of you
while all you fear bug of your code, i like to find and correct bug of
my code, and see my code to run in every places
 
what i can not like is bug or difficult of use / understand / correct
of code, i not wrote [example code library]
possibly i not too much experice...
"chi fa da se fa per tre"
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: