Sunday, October 12, 2014

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

comp.lang.c++@googlegroups.com Google Groups
Unsure why you received this message? You previously subscribed to digests from this group, but we haven't been sending them for a while. We fixed that, but if you don't want to get these messages, send an email to comp.lang.c+++unsubscribe@googlegroups.com.
David Brown <david.brown@hesbynett.no>: Oct 13 12:02AM +0200

On 12/10/14 00:48, JiiPee wrote:
 
> str.size();
 
> so they have to understand that str is an object and it can call its
> member functions, but yes its not too much OO there.
 
str.size() is nothing more than syntactic sugar for size(&str) - it is
not object oriented programming. You could get the same effect in C by
adding nothing more than function overloading.
 
You can get far in programming with C++ without doing any object
oriented programming (though you will probably be using libraries that
use OO behind the scenes).
Paavo Helde <myfirstname@osa.pri.ee>: Oct 12 05:12PM -0500

> don't like to remember doing free() at the end. I want it to be
> automatic. Although maybe C-people can show how to aumatizice this?? I
> guess C programmers use some helper function to do these?
 
No, C people do not believe in "automation" AFAIK. I have understood they
think that this forces the people to be alert and pay attention to details.
The sad part is that when I have spent all my alertness to boring details
there is little left for doing something actually new.
Emanuel Berg <embe8573@student.uu.se>: Oct 13 12:12AM +0200


> IMO, learning proper C++ (strings, STL, exceptions,
> templates etc) should come first, to avoid bad
> habits and wasting time on unneeded C hackery.
 
Well, yeah, but are you sure the order you learn
things will have that big an influence? It is possible
to write very disciplined C.
 
With C++ I think it is possible to get lost with all
the stuff as a beginner. You might also be mislead by
all the OO hype thinking it is the one and only way
(instead of a model to help us think and be better
programmers, just as the equally helpful functional
programming model/paradigm).
 
Thing is with C there aren't nearly as much stuff and
a lot less paradigmic hysteria (now I'm talking like
books, tutorial, etc.). It is more like Lego: here are
a bunch of building blocks that a kid can understand,
just put it together any way you like.
 
But don't let me scare anyone off: there are a lot of
kids who did C++ :)
 
> work under the hood, one should learn some
> C-specific stuff and assembler + CPU architecture. I
> think assembler would be more relevant than C.
 
Well, that depends.
 
If you by "under the hood" mean architecture and/or
hardware (registers, caches, the clock, etc.) - then
yes, it is better to put your energy on assembler than
C. If you already know C++, and not C - again, I think
that is a contradiction in terms but OK - then it
might also be more interesting to take a shot on
assembler, because it will involve a lot more new
stuff and open new doors as the shift is so much more
radical than C++ -> C.
 
But "under the hood" can also mean the OS. And for
OS:s, there is no sweeter language than C, compiling
the end result into a monolithic a.out kernel.
 
--
underground experts united
Paavo Helde <myfirstname@osa.pri.ee>: Oct 12 05:27PM -0500

Emanuel Berg <embe8573@student.uu.se> wrote in
 
> Well, yeah, but are you sure the order you learn
> things will have that big an influence? It is possible
> to write very disciplined C.
 
Sure, but this does not help much if your only goal is to learn C++.
Learning to do really disciplined C is pretty hard and most of the obtained
knowledge is useless in C++.
 
> With C++ I think it is possible to get lost with all
> the stuff as a beginner. You might also be mislead by
> all the OO hype thinking it is the one and only way
 
What OO hype? You sound so much like last century ;-) After the OO hype we
have had template metaprogramming hype in the last decade, not quite sure
what's the hype of this decade.
 
Cheers
Paavo
JiiPee <no@notvalid.com>: Oct 12 11:42PM +0100

On 12/10/2014 23:12, Paavo Helde wrote:
> think that this forces the people to be alert and pay attention to details.
> The sad part is that when I have spent all my alertness to boring details
> there is little left for doing something actually new.
 
Me also I want to do new things and not use time making code which is
not necessary. I want the future of C++ be just like that... more and
more simple and short. There is nothing wrong in that.. just keep the
old C++ also so one can do the pointers etc I needed/wants.
Ian Collins <ian-news@hotmail.com>: Oct 13 11:52AM +1300

Emanuel Berg wrote:
 
> Well, yeah, but are you sure the order you learn
> things will have that big an influence? It is possible
> to write very disciplined C.
 
Very disciplined C can be very poor (or at best not idiomatic) C++.
 
> (instead of a model to help us think and be better
> programmers, just as the equally helpful functional
> programming model/paradigm).
 
Repeating my earlier question, have you read Accelerated C++? It
doesn't introduce OO early on. I think you are fixated on C++ being a
strictly OO language, which is isn't.
 
--
Ian Collins
Robert Hutchings <rm.hutchings@gmail.com>: Oct 12 01:13PM -0500

Some people strongly prefer Slackware....
Ian Collins <ian-news@hotmail.com>: Oct 13 07:18AM +1300

Robert Hutchings wrote:
> Some people strongly prefer Slackware....
 
Others prefer something else.
 
There isn't any real difference when it comes to tools.
 
--
Ian Collins
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 12 07:25PM +0100

On 12/10/2014 19:18, Ian Collins wrote:
>> Some people strongly prefer Slackware....
 
> Others prefer something else.
 
> There isn't any real difference when it comes to tools.
 
Linus hates C++ though.
 
/Flibble
JiiPee <no@notvalid.com>: Oct 12 07:28PM +0100

On 12/10/2014 19:25, Mr Flibble wrote:
 
>> Others prefer something else.
 
>> There isn't any real difference when it comes to tools.
 
> Linus hates C++ though.
 
Yes and very strongly :). But it does not affect using C++ in linux.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 12 07:30PM +0100

On 12/10/2014 19:28, JiiPee wrote:
 
>>> There isn't any real difference when it comes to tools.
 
>> Linus hates C++ though.
 
> Yes and very strongly :). But it does not affect using C++ in linux.
 
Linus hates C++ though.
 
/Flibble
woodbrian77@gmail.com: Oct 12 02:15PM -0700

On Sunday, October 12, 2014 1:13:25 PM UTC-5, Robert Hutchings wrote:
> Some people strongly prefer Slackware....
 
I like FreeBSD and PC-BSD.
 
http://freebsd.org
http://bsdnow.tv
 
Prior to using BSD I was using Arch Linux. I had a TCP
related problem on Linux that I was only able to resolve
by switching to BSD. I was reluctant to switch because
I'd been using Linux for quite a while, but now wish I
had switched earlier. Better late than never.
 
Brian
Ebenezer Enterprises - So far G-d has helped us.
http://webEbenezer.net
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 12 02:34PM -0700

Brian,
 
What are a few things about FreeBSD which
made it more desirable than Linux, prompting
your comment about wishing you would've
switched sooner?
 
Does it use the same GNU tools? Like GNU/
Linux?
 
Please email if you'd like. I'm on my phone
or I would've emailed you.
 
Best regards,
Rick C. Hodgin
woodbrian77@gmail.com: Oct 12 03:31PM -0700

On Sunday, October 12, 2014 4:34:11 PM UTC-5, Rick C. Hodgin wrote:
> made it more desirable than Linux, prompting
> your comment about wishing you would've
> switched sooner?
 
BSD is different from Linux in a lot of ways and
it's taking me a while to adjust to BSD. Now that
I find BSD to be better from a TCP and event
(kqueue vs epoll) perspective, I think it would
have been easier to have switched sooner. Some
things that others like about BSD are Dtrace and
jails. I don't know much about either of those,
but expect to use Dtrace eventually.
 
 
 
> Does it use the same GNU tools? Like GNU/
> Linux?
 
I'm not sure. There are a lot of differences
between things like ps. On Linux I used:
 
ps -elf
 
On BSD it's:
 
ps aux
. That sort of thing comes up often. BSD users
have scripts that depend on the options being one
thing and Linux users likewise, but the options aren't
the same, so it makes it hard to compromise. People
who switch from Linux to BSD should be willing to
be hobbled by the switch. I'm getting by and hope
to eventually become more proficient.
 
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
JiiPee <no@notvalid.com>: Oct 12 07:57PM +0100

On 12/10/2014 19:11, Wouter van Ooijen wrote:
>> std::cout << "arr2 = " << arr2 << std::endl;
 
> Note that you are doing something dangerous here: you ask a string
> (const char pointer) to be printed that is not 0-terminated.
 
Are you talking about this:
const char* str = "comp.lang.c++";
 
?
arnuld <sunrise@invalid.address>: Oct 12 07:46PM

> string (similar to using %s in printf). When the operand has type
> pointer to "object that cannot be a string," the generated code treats
> it the same as using %p in printf.
 
But arr2 is an array of chars not terminated by null character:
 
char arr2[] = {'a','b','c'};

Still it prints it correctly. How does std::cout know where to stop.
Where I can find about rules regarding this ?

 
 
 
--
arnuld
http://lispmachine.wordpress.com/
arnuld <sunrise@invalid.address>: Oct 12 08:08PM

> On Sun, 12 Oct 2014 19:57:26 +0100, JiiPee wrote:
 
> Are you talking about this:
> const char* str = "comp.lang.c++";

No. He was talking about this:
 
char arr2[] = {'a','b','c'};
 
 
 
 
--
arnuld
http://lispmachine.wordpress.com/
JiiPee <no@notvalid.com>: Oct 12 09:27PM +0100

On 12/10/2014 21:08, arnuld wrote:
 
> char arr2[] = {'a','b','c'};
 
But arr2 is not const char pointer, is it? its a char pointer... we can
change its content.
JiiPee <no@notvalid.com>: Oct 12 09:38PM +0100

On 12/10/2014 20:46, arnuld wrote:
 
> char arr2[] = {'a','b','c'};
 
> Still it prints it correctly. How does std::cout know where to stop.
> Where I can find about rules regarding this ?
 
on my GCC it does not print arr2 correctly... it adds a return at the
end of it when I do:
 
printf("the size of %s is %d and the length is %d\n\n",
arr2, sizeof(arr2), strlen(arr2));
 
if I use arr2[] = "abc" it works.
 
I guess its behaviour is undefined.. in some machines its correct in
some not.
Richard Damon <Richard@Damon-Family.org>: Oct 12 05:20PM -0400

On 10/12/14, 4:38 PM, JiiPee wrote:
 
> if I use arr2[] = "abc" it works.
 
> I guess its behaviour is undefined.. in some machines its correct in
> some not.
 
It depends on what follows it in memory. Working sometimes and not
others is very possible undefined behavior (sometimes undefined behavior
is what you want, but don't count on it, which can make it a very hard
bug to find.)
 
Since before it is an int, which likely will be aligned to at least a 2
byte boundary, (even more likely a 4 byte, maybe an 8), and the double
after will likely want to be aligned to 4 or 8 bytes too, the 3 byte
char array is almost certainly going to have a padding byte (or more)
added after it. The compiler might force that byte(s) to 0, or it might
leave it to a random value.
Wouter van Ooijen <wouter@voti.nl>: Oct 12 11:33PM +0200

JiiPee schreef op 12-Oct-14 10:27 PM:
 
> But arr2 is not const char pointer, is it? its a char pointer... we can
> change its content.
 
You are correct in that. But the arr2 is still dangerous to print, as
others have already spelled out. Accessing array elements beyond the
array itself (which is what will happen when operator<< tries to print
this char array) is undefined behaviour.
 
Wouter
JiiPee <no@notvalid.com>: Oct 12 10:37PM +0100

On 12/10/2014 22:20, Richard Damon wrote:
> byte char array is almost certainly going to have a padding byte (or
> more) added after it. The compiler might force that byte(s) to 0, or
> it might leave it to a random value.
 
in an error case it will be printed:
 
the size of abc
is 3 ...
JiiPee <no@notvalid.com>: Oct 12 10:39PM +0100

On 12/10/2014 22:33, Wouter van Ooijen wrote:
> others have already spelled out. Accessing array elements beyond the
> array itself (which is what will happen when operator<< tries to print
> this char array) is undefined behaviour.
 
yes i know, it printed wrongly on my machine
Ike Naar <ike@iceland.freeshell.org>: Oct 12 10:04PM


> But arr2 is an array of chars not terminated by null character:
 
> char arr2[] = {'a','b','c'};
 
> Still it prints it correctly.
 
You were lucky.
 
> How does std::cout know where to stop.
 
Most probably the byte following the 'c' in memory, by chance, happened
to be a null byte.
But that's not something you can rely on if you write your code like that.
Paavo Helde <myfirstname@osa.pri.ee>: Oct 12 09:02AM -0500

> std::string class. But if its a private member then it would be ok.
> The functions calling it can be friends so they can get access to
> private clone().
 
std::string is not a polymorphic class so it does not need a clone
function. In general, fundamental value classes (like std::string) cannot
have any virtual methods as this might hinder their usability (think an
array of million strings, this would be a million wasted vtable pointers).
 
Cheers
P
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: