Tuesday, February 18, 2014

comp.lang.c++ - 25 new messages in 4 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* about gets - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0335e4afbf8afe82?hl=en
* beginner - 7 messages, 7 authors
http://groups.google.com/group/comp.lang.c++/t/764088b8acc86a74?hl=en
* pointer to a vector - 9 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/b17f744707f37fdb?hl=en
* Can't think of a good subject - 8 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en

==============================================================================
TOPIC: about gets
http://groups.google.com/group/comp.lang.c++/t/0335e4afbf8afe82?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 11 2014 9:33 am
From: Victor Bazarov


On 2/11/2014 12:22 PM, mary8shtr@gmail.com wrote:
> hi.I am writing a program.while i define some variable but program say this variable undefined.
>

http://www.parashift.com/c++-faq/posting-code.html

V
--
I do not respond to top-posted replies, please don't ask





==============================================================================
TOPIC: beginner
http://groups.google.com/group/comp.lang.c++/t/764088b8acc86a74?hl=en
==============================================================================

== 1 of 7 ==
Date: Wed, Feb 12 2014 10:01 am
From: frank cubi


Which is the most appropriate website for a person who is learning c++ ?




== 2 of 7 ==
Date: Wed, Feb 12 2014 10:14 am
From: ram@zedat.fu-berlin.de (Stefan Ram)


frank cubi <frankcubi7@gmail.com> writes:
>Which is the most appropriate website for a person who is learning c++ ?

I know some good books:

You can read (in this order and doing the exercise):
Programming -- Principles and Practice Using C++ (only if
you have not programmed before) or Accelerated C++ (if you
have programmed before), The C++ Programming Language,
Effective C++, Exceptional C++ (Parts 1 and 2), Modern
C++ programming, and ISO/IEC 14882:2011.

There also might be websites with similar contents, but
I am not aware of them.





== 3 of 7 ==
Date: Wed, Feb 12 2014 11:03 am
From: Paavo Helde


frank cubi <frankcubi7@gmail.com> wrote in news:9c118022-a702-413b-8ea8-
32da6f631e26@googlegroups.com:

> Which is the most appropriate website for a person who is learning c++ ?

http://www.parashift.com/c++-faq/ is a good one.




== 4 of 7 ==
Date: Wed, Feb 12 2014 11:23 am
From: Cholo Lennon


On 02/12/2014 04:03 PM, Paavo Helde wrote:
> frank cubi <frankcubi7@gmail.com> wrote in news:9c118022-a702-413b-8ea8-
> 32da6f631e26@googlegroups.com:
>
>> Which is the most appropriate website for a person who is learning c++ ?
>
> http://www.parashift.com/c++-faq/ is a good one.
>

Stroustrup's homepage and ISO C++ are also good websites:

http://www.stroustrup.com/
http://isocpp.org/get-started


Regards

--
Cholo Lennon
Bs.As.
ARG




== 5 of 7 ==
Date: Wed, Feb 12 2014 11:27 am
From: Jorgen Grahn


On Wed, 2014-02-12, Stefan Ram wrote:
> frank cubi <frankcubi7@gmail.com> writes:
>>Which is the most appropriate website for a person who is learning c++ ?
>
> I know some good books:
>
> You can read (in this order and doing the exercise):
> Programming -- Principles and Practice Using C++ (only if
> you have not programmed before) or Accelerated C++ (if you
> have programmed before), The C++ Programming Language,
> Effective C++, Exceptional C++ (Parts 1 and 2), Modern
> C++ programming, and ISO/IEC 14882:2011.
>
> There also might be websites with similar contents, but
> I am not aware of them.

Me neither. https://www.sgi.com/tech/stl/ is the only one I use. And
/The C++ Programming Language/ is the only book I've read and liked.
However, this mostly means I learned C++ slowly, and started a long
time ago ...

Apart from that I recommend:
- writing lots of code
- reading lots of code
- learning your tools
- hanging out on comp.lang.c++ and comp.lang.c++.moderated

Happy hacking!

/Jorgen

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




== 6 of 7 ==
Date: Wed, Feb 12 2014 1:16 pm
From: woodbrian77@gmail.com


On Wednesday, February 12, 2014 1:27:31 PM UTC-6, Jorgen Grahn wrote:
> On Wed, 2014-02-12, Stefan Ram wrote:
>
> > frank cubi <frankcubi7@gmail.com> writes:
>
> >>Which is the most appropriate website for a person who is learning c++ ?
>
> >
>
> > I know some good books:
>
> >
>
> > You can read (in this order and doing the exercise):
>
> > Programming -- Principles and Practice Using C++ (only if
>
> > you have not programmed before) or Accelerated C++ (if you
>
> > have programmed before), The C++ Programming Language,
>
> > Effective C++, Exceptional C++ (Parts 1 and 2), Modern
>
> > C++ programming, and ISO/IEC 14882:2011.
>
> >
>
> > There also might be websites with similar contents, but
>
> > I am not aware of them.
>
>
>
> Me neither. https://www.sgi.com/tech/stl/ is the only one I use. And
> /The C++ Programming Language/ is the only book I've read and liked.
> However, this mostly means I learned C++ slowly, and started a long
> time ago ...
>
> Apart from that I recommend:
> - writing lots of code
> - reading lots of code

I have an archive here:

http://webEbenezer.net/build_integration.html

That you're welcome to download and read.
The code uses some of the newer features
of the language.

Brian
Ebenezer Enterprises
http://webEbenezer.net




== 7 of 7 ==
Date: Wed, Feb 12 2014 1:44 pm
From: "K. Frank"


Hello Frank!

On Wednesday, February 12, 2014 1:01:15 PM UTC-5, frank cubi wrote:
> Which is the most appropriate website for a person who is learning c++ ?

As Paavo mentioned,

http://www.parashift.com/c++-faq/

is a good place to start.

(Some minor caveats: It can be a little overly prescriptive;
it's philosophy is a bit too narrowly object oriented; and
it's showing its age a little. One pet peeve of mind is that
the web site's format became overly fragmented a few years ago.)

For features added in the most recent standard (already a few
years ago) Stroustrup's C++11 FAQ is very good:

http://www.stroustrup.com/C++11FAQ.html

Two good (not perfect) reference sites are:

http://en.cppreference.com/w/

and

http://www.cplusplus.com/reference/

(or if you prefer, http://www.cplusplus.com/).

Stefan's book suggestions are very good.

Also, although not technically a web site, this usenet group
(or its moderated companion, comp.lang.c++.moderated) is a
good place to post specific, single-topic questions when you
come across something you don't understand or don't see how
to do. (If you're learning, you'll get better answers if
you do your homework first.)


Happy Hacking!


K. Frank





==============================================================================
TOPIC: pointer to a vector
http://groups.google.com/group/comp.lang.c++/t/b17f744707f37fdb?hl=en
==============================================================================

== 1 of 9 ==
Date: Wed, Feb 12 2014 11:46 am
From: "A"


There are 2 vectors each one having a structure

struct MyStruct
{
int a;
std::string b;
}

std::vector<MyStruct> v1;
std::vector<MyStruct> v2;

Now I want a pointer to which one I will use... v1 or v2

std::vector<MyStruct> *v = (condition)? &v1 : &v2;

Finally I access it using:

for (unsigned i = 0; i < v->size(); i++)
{
v->operator[](i).a = i + 1;
}

My lack of understanding here is:

a) does the above *v needs to be deleted? Isn't it just a pointer variable?
Or it works differently when it points to a vector? Just to be clear, I
don't actually need to delete v1 or v2. I just need to cleanup *v if
required.

b) what's the heap or stack or difference or advantage of them in relation
to the above?






== 2 of 9 ==
Date: Wed, Feb 12 2014 11:51 am
From: "A"


Actually I just found that I can use *v like this:

(*v)[i].a = i + 1;

Cleaner to me than

v->operator[](i).a = i + 1;

However, my questions are still the same.






== 3 of 9 ==
Date: Wed, Feb 12 2014 12:11 pm
From: Paavo Helde


"A" <a@a.a> wrote in news:ldgj2i$2gc$1@gregory.bnet.hr:

> There are 2 vectors each one having a structure
>
> struct MyStruct
> {
> int a;
> std::string b;
> }
>
> std::vector<MyStruct> v1;
> std::vector<MyStruct> v2;
>
> Now I want a pointer to which one I will use... v1 or v2
>
> std::vector<MyStruct> *v = (condition)? &v1 : &v2;
>
> Finally I access it using:
>
> for (unsigned i = 0; i < v->size(); i++)
> {
> v->operator[](i).a = i + 1;
> }

You can also use references:

std::vector<MyStruct> & v = (condition)? v1 : v2;
...
v[i].a = i+1;

>
> My lack of understanding here is:
>
> a) does the above *v needs to be deleted? Isn't it just a pointer
> variable? Or it works differently when it points to a vector? Just to
> be clear, I don't actually need to delete v1 or v2. I just need to
> cleanup *v if required.

No, as a rule of thumb, if your code does not contain 'new' then there is
no need for 'delete' either (and this is a good thing). Any dynamically
allocated memory is maintained and released by the std::vector objects
internally.

>
> b) what's the heap or stack or difference or advantage of them in
> relation to the above?

std::vector automatically stores the stuff in the right place, you do not
need to worry about this. Just avoid raw arrays and 'new' (as you have
done so far) and you should be fine.

Cheers
Paavo








== 4 of 9 ==
Date: Wed, Feb 12 2014 12:12 pm
From: Jorgen Grahn


On Wed, 2014-02-12, A wrote:
> There are 2 vectors each one having a structure
>
> struct MyStruct
> {
> int a;
> std::string b;
> }
>
> std::vector<MyStruct> v1;
> std::vector<MyStruct> v2;
>
> Now I want a pointer to which one I will use... v1 or v2
>
> std::vector<MyStruct> *v = (condition)? &v1 : &v2;

You don't need a pointer below -- a reference would have worked just
as well, and the syntax would have been cleaner.

> Finally I access it using:
>
> for (unsigned i = 0; i < v->size(); i++)
> {
> v->operator[](i).a = i + 1;
> }
>
> My lack of understanding here is:
>
> a) does the above *v needs to be deleted? Isn't it just a pointer variable?

No, and yes. You haven't done 'new', so you're not responsible for
doing 'delete'. BTW, both of those are rarely needed in modern code
-- if you use them a lot you're probably doing something wrong.

> Or it works differently when it points to a vector? Just to be clear, I
> don't actually need to delete v1 or v2. I just need to cleanup *v if
> required.

No cleanup required. But I don't really understand what you're trying
to say ...

> b) what's the heap or stack or difference or advantage of them in relation
> to the above?

I don't understand that question. Please rephrase.

/Jorgen

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




== 5 of 9 ==
Date: Wed, Feb 12 2014 12:32 pm
From: "A"


"Jorgen Grahn" <grahn+nntp@snipabacken.se> wrote in message
news:slrnlfnle0.81f.grahn+nntp@frailea.sa.invalid...
> No, and yes. You haven't done 'new', so you're not responsible for
> doing 'delete'. BTW, both of those are rarely needed in modern code
> -- if you use them a lot you're probably doing something wrong.

No, I don't use normally new or delete. I use boost smart pointers and
vectors.
Good thing to know this rule of a thumb - using new = delete, not using it,
then it is just a pointer.

> No cleanup required. But I don't really understand what you're trying
> to say ...

What I though is that if it is pointer to a vector then it is somehow
different but obviously it is just a same pointer like any other. So yes,
then no cleanup is required, it is just a pointer variable.

>> b) what's the heap or stack or difference or advantage of them in
>> relation
>> to the above?
> I don't understand that question. Please rephrase.

A guy here was mentioning heap so I though it was related. Seems it is not:
http://facepunch.com/showthread.php?t=780439






== 6 of 9 ==
Date: Wed, Feb 12 2014 12:34 pm
From: "A"


"Paavo Helde" <myfirstname@osa.pri.ee> wrote in message
news:XnsA2D2E1C8E2580myfirstnameosapriee@216.196.109.131...
> No, as a rule of thumb, if your code does not contain 'new' then there is
> no need for 'delete' either (and this is a good thing). Any dynamically
> allocated memory is maintained and released by the std::vector objects
> internally.

That's a good rule to remember. So it is just a plain pointer. Thanks!

> std::vector automatically stores the stuff in the right place, you do not
> need to worry about this. Just avoid raw arrays and 'new' (as you have
> done so far) and you should be fine.

Yes, haven't been using new/delete in years since I discovered smart
pointers and vectors.






== 7 of 9 ==
Date: Wed, Feb 12 2014 12:43 pm
From: ram@zedat.fu-berlin.de (Stefan Ram)


"A" <a@a.a> writes:
>There are 2 vectors each one having a structure
>std::vector<MyStruct> v1;
>std::vector<MyStruct> v2;

IIRC, the default constructor constructs an /empty/ vector.
This means that /neither/ vector so far has a structure.





== 8 of 9 ==
Date: Wed, Feb 12 2014 1:01 pm
From: Jorgen Grahn


On Wed, 2014-02-12, A wrote:
> "Jorgen Grahn" <grahn+nntp@snipabacken.se> wrote in message
> news:slrnlfnle0.81f.grahn+nntp@frailea.sa.invalid...

[...]

>>> b) what's the heap or stack or difference or advantage of them in
>>> relation
>>> to the above?
>> I don't understand that question. Please rephrase.
>
> A guy here was mentioning heap so I though it was related. Seems it is not:
> http://facepunch.com/showthread.php?t=780439

I don't know which of them, but several of them seem rather confused.
You'll get better answers here, with the right questions.

/Jorgen

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




== 9 of 9 ==
Date: Thurs, Feb 13 2014 5:23 am
From: "A"


"Stefan Ram" <ram@zedat.fu-berlin.de> wrote in message
news:vector-20140212214210@ram.dialup.fu-berlin.de...
> IIRC, the default constructor constructs an /empty/ vector.
> This means that /neither/ vector so far has a structure.

Of course, I know that - that was just a dumb example. Thanks for pointing
this out though. Much appreciate the effort.







==============================================================================
TOPIC: Can't think of a good subject
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en
==============================================================================

== 1 of 8 ==
Date: Wed, Feb 12 2014 7:45 pm
From: woodbrian77@gmail.com



I'm not sure why the behavior of the following
two functions differs here. The only difference
in these functions is in the body of the loop.

template <class R>
void Receive (::cmw::ReceiveBuffer<R>& buf
,empty_container<cmw::File>& az1)
{
int32_t count[1];
count[0]=buf.template Give<uint32_t>();
for(;count[0]>0;--count[0]){
cmw::File inst(buf); // named
}
}


template <class R>
void Receive (::cmw::ReceiveBuffer<R>& buf
,empty_container<cmw::File>& az1)
{
int32_t count[1];
count[0]=buf.template Give<uint32_t>();
for(;count[0]>0;--count[0]){
cmw::File (buf);
}
}


The first (named) version works the way I want
it to, and the second version, built with either
gcc or clang doesn't. Both compilers are
producing smaller text segments for the second
version. And the results for that version
(both compilers) are like nothing is being done
in the loop.

Can someone explain this? In another file I
have some code similar to the second version
and it works fine:

while(fgets(lineBuf,300,Fl.FlHndl)){
token=strtok(lineBuf," ");
if(strcmp("Header",token)) break;
cmw::File (strtok(nullptr,"\n ")).Marshal(buf);
}

I've simplified that loop a little, but don't
think I've removed anything important. There
are different constructors being used in these
two cases.

http://webEbenezer.net/misc/File.hh

Thanks.

Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net




== 2 of 8 ==
Date: Thurs, Feb 13 2014 9:00 am
From: Bo Persson


woodbrian77@gmail.com skrev 2014-02-13 04:45:
>
> I'm not sure why the behavior of the following
> two functions differs here. The only difference
> in these functions is in the body of the loop.
>
> template <class R>
> void Receive (::cmw::ReceiveBuffer<R>& buf
> ,empty_container<cmw::File>& az1)
> {
> int32_t count[1];
> count[0]=buf.template Give<uint32_t>();
> for(;count[0]>0;--count[0]){
> cmw::File inst(buf); // named
> }
> }
>
>
> template <class R>
> void Receive (::cmw::ReceiveBuffer<R>& buf
> ,empty_container<cmw::File>& az1)
> {
> int32_t count[1];
> count[0]=buf.template Give<uint32_t>();
> for(;count[0]>0;--count[0]){
> cmw::File (buf);
> }
> }
>
>
> The first (named) version works the way I want
> it to, and the second version, built with either
> gcc or clang doesn't. Both compilers are
> producing smaller text segments for the second
> version. And the results for that version
> (both compilers) are like nothing is being done
> in the loop.

The second version also declares a named variable, buf. Parenthesis are
optional when declaring variables.


Bo Persson






== 3 of 8 ==
Date: Thurs, Feb 13 2014 10:53 am
From: woodbrian77@gmail.com


On Thursday, February 13, 2014 11:00:01 AM UTC-6, Bo Persson wrote:
> woodbrian77@gmail.com skrev 2014-02-13 04:45:
>
>
> > The first (named) version works the way I want
> > it to, and the second version, built with either
> > gcc or clang doesn't. Both compilers are
> > producing smaller text segments for the second
> > version. And the results for that version
> > (both compilers) are like nothing is being done
> > in the loop.
>
> The second version also declares a named variable, buf. Parenthesis are
> optional when declaring variables.
>

OK, I see what you mean. Is there a way to
tell the compiler I want an anonymous File
object to be constructed using the buf object?





== 4 of 8 ==
Date: Thurs, Feb 13 2014 10:59 am
From: Alain Ketterlin


Bo Persson <bop@gmb.dk> writes:

> woodbrian77@gmail.com skrev 2014-02-13 04:45:

>> template <class R>
>> void Receive (::cmw::ReceiveBuffer<R>& buf
>> ,empty_container<cmw::File>& az1)
>> {
>> int32_t count[1];
>> count[0]=buf.template Give<uint32_t>();
>> for(;count[0]>0;--count[0]){
>> cmw::File inst(buf); // named
>> }
>> }
>>
>> template <class R>
>> void Receive (::cmw::ReceiveBuffer<R>& buf
>> ,empty_container<cmw::File>& az1)
>> {
>> int32_t count[1];
>> count[0]=buf.template Give<uint32_t>();
>> for(;count[0]>0;--count[0]){
>> cmw::File (buf);
>> }
>> }
>>
>> The first (named) version works the way I want
>> it to, and the second version, built with either
>> gcc or clang doesn't.

What way do you want it to "work"?

>> Both compilers are producing smaller text segments for the second
>> version. And the results for that version (both compilers) are like
>> nothing is being done in the loop.
>
> The second version also declares a named variable, buf. Parenthesis
> are optional when declaring variables.

Hmm, I think the second version creates a temporary (with buf as a
parameter to the constructor), which is not used and therefore
eliminated by the compiler. What part of the standard this behavior is
based on I don't know.

-- Alain.




== 5 of 8 ==
Date: Thurs, Feb 13 2014 11:27 am
From: red floyd


On 2/13/2014 10:53 AM, woodbrian77@gmail.com wrote:
> On Thursday, February 13, 2014 11:00:01 AM UTC-6, Bo Persson wrote:
>> woodbrian77@gmail.com skrev 2014-02-13 04:45:
>>
>>
>>> The first (named) version works the way I want
>>> it to, and the second version, built with either
>>> gcc or clang doesn't. Both compilers are
>>> producing smaller text segments for the second
>>> version. And the results for that version
>>> (both compilers) are like nothing is being done
>>> in the loop.
>>
>> The second version also declares a named variable, buf. Parenthesis are
>> optional when declaring variables.
>>
>
> OK, I see what you mean. Is there a way to
> tell the compiler I want an anonymous File
> object to be constructed using the buf object?
>
Accidentally hit "reply" instead of "followup".

I think you need to put double parens around "buf".
It's very similar to the "most vexing parse" situation.




== 6 of 8 ==
Date: Thurs, Feb 13 2014 2:10 pm
From: woodbrian77@gmail.com


On Thursday, February 13, 2014 1:27:30 PM UTC-6, red floyd wrote:
> On 2/13/2014 10:53 AM, woodbrian77@gmail.com wrote:
>
> > On Thursday, February 13, 2014 11:00:01 AM UTC-6, Bo Persson wrote:
>
> >> The second version also declares a named variable, buf. Parenthesis are
> >> optional when declaring variables.
>
> >>
>
> > OK, I see what you mean. Is there a way to
> > tell the compiler I want an anonymous File
> > object to be constructed using the buf object?
> >
>
> Accidentally hit "reply" instead of "followup".
>

I'm not aware of a followup option. I just hit reply.

> I think you need to put double parens around "buf".

I didn't mention it in my original post, but I did
try that and just tried it again. Both compilers
produce the same output, according to the cmp command,
for

cmw::File (buf);

and

cmw::File ((buf));

I wasn't really sure why I thought of trying that,
but probably had read somewhere where that had
helped someone.


> It's very similar to the "most vexing parse" situation.

I was afraid of that also, but decided to post
because I wasn't figuring it out here.


Brian
Ebenezer Enterprises
http://webEbenezer.net




== 7 of 8 ==
Date: Thurs, Feb 13 2014 2:29 pm
From: woodbrian77@gmail.com


On Thursday, February 13, 2014 12:59:42 PM UTC-6, Alain Ketterlin wrote:
> Bo Persson <bop@gmb.dk> writes:
>
>
>
> > woodbrian77@gmail.com skrev 2014-02-13 04:45:
>
> >>
> >> The first (named) version works the way I want
> >> it to, and the second version, built with either
> >> gcc or clang doesn't.
>
> What way do you want it to "work"?
>

I'm looking for something analogous to this:

while(fgets(lineBuf,300,Fl.FlHndl)){
token=strtok(lineBuf," ");
if(strcmp("Header",token)) break;
cmw::File (strtok(nullptr,"\n ")).Marshal(buf);
}

That creates an anonymous File object.

> >> Both compilers are producing smaller text segments for the second
> >> version. And the results for that version (both compilers) are like
> >> nothing is being done in the loop.
> >
>
> > The second version also declares a named variable, buf. Parenthesis
> > are optional when declaring variables.
>
> Hmm, I think the second version creates a temporary (with buf as a
> parameter to the constructor), which is not used and therefore
> eliminated by the compiler.
>

That's what I was thinking might be happening originally,
but I think what Bo wrote is correct. At least according
to the cmp command, there's no difference between:

cmw::File buf;

and

cmw::File (buf);

for either compiler.


Brian
Ebenezer Enterprises
http://webEbenezer.net




== 8 of 8 ==
Date: Thurs, Feb 13 2014 2:46 pm
From: woodbrian77@gmail.com



Just to clarify, both compilers produce the same
output, according to the cmp command, for these
three forms:

cmw::File buf;

cmw::File (buf);

cmw::File ((buf));





==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: