Follow Slashdot blog updates by subscribing to our blog RSS feed


Forgot your password?
Slashdot Deals: Deal of the Day - Pay What You Want for the Learn to Code Bundle, includes AngularJS, Python, HTML5, Ruby, and more. ×

Comment Re:Apartheid (Score 1) 441

It is always funny to see how identical the responses of the apes... sorry believers... are when one points to their barbarity.

Communism: There never was communism. Stalin was no communist. Pretended to be communist for his political agenda. Yadda, yadda.

"Chrisianism": No, no, not those where not Christians. Those were Atheists. Pretending to be Christians for their political agenda. Yadda, yadda.

Btw... it does not matter about what Hitlers spoke in this video. It matters that the claims the a Christian. And he was. A very good one.

Comment I regularly go to a C++ user group in my area. (Score 1) 473

Meeting once a month. It is free. Roughly 10-20 members. I learned plenty there. It is very interesting since the members come from all kinds of backgrounds. The techniques an methods of C++ developers vary tremendously. What has this to do with this article? Simple, in all my years in this group I did not see a single parasite there.

Comment Re:slashdot and languages (Score 1) 336

You should read this:

If no user-defined constructors of any kind are provided for a class type (struct, class, or union), the compiler will always declare a default constructor as an inline public member of its class.

So your Because: it has no ctor!! is definitely wrong. There are no structs, classes, or unions without a constructor. Never. Right is that i in B is not initialized because:

If the implicitly-declared default constructor is not deleted or trivial, it is defined (that is, a function body is generated and compiled) by the compiler, and it has exactly the same effect as a user-defined constructor with empty body and empty initializer list. That is, it calls the default constructors of the bases and of the non-static members of this class.

i is non-static, but a POD type -> no constructor, no default initialization. D has a constructor, which initializes s and calls the implicitly-declared default constructor in B, but this still does nothing for i, since B's default constructor is trivial:

Trivial default constructor

The default constructor for class T is trivial (i.e. performs no action) if all of the following is true:

  • The constructor is not user-provided (i.e., is implicitly-defined or defaulted)

  • T has no virtual member functions

  • T has no virtual base classes

    T has no non-static members with brace-or-equal initializers. (since C++11)


  • Every direct base of T has a trivial default constructor

  • Every non-static member of class type has a trivial default constructor

A trivial default constructor is a constructor that performs no action. Objects with trivial default constructors can be created by using reinterpret_cast on any suitably aligned storage, e.g. on memory allocated with std::malloc. All data types compatible with the C language (POD types) are trivially default-constructible.

i is in B as uninitalized as it is in D. No difference.

Comment Re:slashdot and languages (Score 1) 336

You did see, that I corrected my answer? Yes, I answered a bit too quickly. But for me the whole problem is irrelevant. From my earliest contacts with computer languages, it was BASIC in the early 80th, I have been taught: You initialize your variables. And this is exactly what I am doing. I have yet to see a problem where the few cycles for a possibly unneeded initialization make a difference. So this initialization problem is nothing I have constantly in my mind, And constructors wrong? You neither defined any of the four possible constructors, nor the destructor... and this means you get the defaults. And this has nothing to do with 'when needed', only with 'did I provide one myself, so the others are compiler generated or not?'.

And initialization of non-static member variables depend on compilation unit? Again, IMHO irrelevant, but please, show me the paragraf in the C++ standard. Please do, I am really interested. AFAIK only static or global variable build-in types get a default initialization. And I don't care for globals. Not only that I don't use them, I have not even seen them used in other ppls code in years.
I still have the nagging feeling, that somehow you mean the 'static initialization order fiasco', which can also happen with globals, and where the translation unit matters... only that this has nothing to do with the code you posted.

But yes, there can be initialization problems in C++, which are relevant and which really can be important.. and I admit, I also don't have constantly in my mind, because it is a rare problem: When deeper hierarchies of multi inheritance (virtual and not virtual) are used. But so what? I know the problem and if needed I look into the specs for a fresh up.

Do you really want to tell me that no other language has less used features, or pitfalls, which are simply irrelevant when good coding styles are used?

Comment Re:slashdot and languages (Score 1) 336

Who cares what b.i and d.i are? They are private and in your example inaccessible anyways. If you ignore that than b.i and d.i are both 0. Thats the default initialisation for build-in types when no user defined constructor is in your example. Furthermore class B has no virtual destructor -> You don't inherit from it. It is irrelevant whether B and D are in different compile units or not.

"a constructor for a class is auto generated by the compiler when needed"

What constructor? I know four.

Be careful when a loop exits to the same place from side and bottom.