Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

www.equestionanswers.com - C,C++, VC++,MFC,COM,DCOM, DLL question and answers for interviews and self-study

40 views
Skip to first unread message

EQuestionAnswers Inc

unread,
Dec 28, 2014, 1:42:27 AM12/28/14
to
Hi,

This is our website http://www.equestionanswers.com loaded with C,C++, VC++,MFC,COM,DCOM, DLL question and answers, targeted for interviews and self-study. Hope you like this forum.

Thanks and regards,
webmaster

Ian Collins

unread,
Dec 28, 2014, 2:09:59 AM12/28/14
to
EQuestionAnswers Inc wrote:
> Hi,
>
> This is our website http://www.equestionanswers.com loaded with
> C,C++, VC++,MFC,COM,DCOM, DLL question and answers, targeted for
> interviews and self-study. Hope you like this forum.

With examples like this:

#include
template
T swap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
void main()
{
int i = 10, j = 20;
swap(i, j);
cout << "Values i, j " << i << ", " << j;
float a = 3.14, b = -6.28;
swap(a, b);
cout << "Values a, b " << a << ", " << b;
}

One to avoid.

--
Ian Collins

JiiPee

unread,
Dec 28, 2014, 6:57:00 AM12/28/14
to
yes should be like:

|template <class T>void swap (T& a, T& b)
{
T c(std::move(a)); a=std::move(b); b=std::move(c);
}

Isn't it? Lets say a and b are objects containing 1 million characters. Then the
swap would copy 3 times those arrays. But with move copy would not be done. Right?

Or does the optimizer possibly do/add move automatically even if doing the swap without
std::move? I guess not in this case.


|


JiiPee

unread,
Dec 28, 2014, 7:00:19 AM12/28/14
to
On 28/12/2014 07:09, Ian Collins wrote:
oh yeah, and the
#include
template

and no return (or rather should have void), heh. But also that move
should be used, isn't it?

Ian Collins

unread,
Dec 28, 2014, 2:03:42 PM12/28/14
to
I wasn't even looking at the details, there where so many other errors
it wasn't worth the trouble.

As soon as anyone sees "void main()" in an example, the only safe option
is to close the browser tab!

--
Ian Collins

JiiPee

unread,
Dec 28, 2014, 2:08:12 PM12/28/14
to
ye the void as well. So it would be like 4 issues total I guess ?

Also imo best return is: return EXIT_SUCCESS;
I dont like return 0; :)

Juha Nieminen

unread,
Jan 2, 2015, 7:22:00 AM1/2/15
to
JiiPee <n...@notvalid.com> wrote:
> Also imo best return is: return EXIT_SUCCESS;
> I dont like return 0; :)

Doesn't the C++ standard state that a returnless main() will return
EXIT_SUCCESS by default? Thus it's ok to not write any return at all
(unless you want to return an error code).

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Jorgen Grahn

unread,
Jan 2, 2015, 7:39:50 AM1/2/15
to
On Fri, 2015-01-02, Juha Nieminen wrote:
> JiiPee <n...@notvalid.com> wrote:
>> Also imo best return is: return EXIT_SUCCESS;
>> I dont like return 0; :)
>
> Doesn't the C++ standard state that a returnless main() will return
> EXIT_SUCCESS by default? Thus it's ok to not write any return at all
> (unless you want to return an error code).

On the other hand, few programs can honestly say "I will always
succeed" ...

/Jorgen

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

Robert Wessel

unread,
Jan 2, 2015, 11:33:06 AM1/2/15
to
On Fri, 2 Jan 2015 12:21:50 +0000 (UTC), Juha Nieminen
<nos...@thanks.invalid> wrote:

>JiiPee <n...@notvalid.com> wrote:
>> Also imo best return is: return EXIT_SUCCESS;
>> I dont like return 0; :)
>
>Doesn't the C++ standard state that a returnless main() will return
>EXIT_SUCCESS by default? Thus it's ok to not write any return at all
>(unless you want to return an error code).


C++98 will return zero (which is like, but not identical to,
EXIT_SUCCESS). C99 and later are the same, but C89 allows the form
(no return at the end of main), but leaves the actual value returned
to the OS undefined.

Barry Schwarz

unread,
Jan 2, 2015, 1:21:18 PM1/2/15
to
On Fri, 2 Jan 2015 12:21:50 +0000 (UTC), Juha Nieminen
<nos...@thanks.invalid> wrote:

>JiiPee <n...@notvalid.com> wrote:
>> Also imo best return is: return EXIT_SUCCESS;
>> I dont like return 0; :)
>
>Doesn't the C++ standard state that a returnless main() will return
>EXIT_SUCCESS by default? Thus it's ok to not write any return at all
>(unless you want to return an error code).

If by OK you mean well defined, then yes. If you mean good style or
compliant with organization standards, maybe at best.

--
Remove del for email
0 new messages