Become a fan of Slashdot on Facebook


Forgot your password?
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×

Comment Re:Not obvious at all it is problematic (Score 1) 586

C++'s STL fixes this with for_each, transform, and accumulate. All three are looping constructs over a range, but each one has well-defined termination and meaning. For example if I want to visit each element once, I'd use

for_each(begin(container), end(container), some_action);

If I want to mutate it,

transform(begin(container), end(container), begin(destination), some_transforming_action);

and if I want to collapse it down into a scalar,

some_type result = accumulate(begin(container), end(container), initial_value, some_operation);

If you squint at it enough it almost looks like a declarative language, and the compiler is usually smart enough to inline those function calls!

Comment Re:I guess you don't understand languages either (Score 1) 594

You can simulate inheritance in C: just store an instance of the parent struct in the derived struct, and you can access inherited members via self->parent->method( );

Similarily for polymorphism: just cast it to a pointer to the base struct. If you lay your struct out nicely memory-wise this should be a safe operation.

If you can write it in assembly you can write it in C. And all that fancy C++ stuff has to eventually make its way down to ASM at some point.

Comment Re:One good reason... (Score 2) 793

Value templates can be great. Have a look at std::array. Under the hood it's just a static C-style array (take a look at the generated assembly, on a decent compiler there's zero added overhead), but it remembers it's size as it's baked into the type itself. So it gives us all the speed of a C-style stack-allocated array of N items, plus removes the hassle of having to pass the size around as an extra parameter to functions. Finally, if you really want to be safe, you can use the .at( ) member function for range-checked access. The operator [ ] is overloaded of course for direct access, in case you need that too. This functionality would be impossible without the ability to use std::size_t as a template parameter.

Comment Re:end is harder to read (Score 1) 140

I never said I was a bad typer, just a slower typer. I probably would be better off if I were a better (faster) typer, but as I am I'm still more productive than the majority of programmers I've worked with, many of which who type a lot faster than I do.

Comment Re:So it works the way Stallman envisioned? (Score 1) 191

There is nothing in the GPL License that says they have to make their own improvements available. All that is required is that IF they decide to make their improvements available, they have to provide the source. They can even charge for the improvements, but as long as the source is available then they're in the clear.

Comment Re:struct vs. class (Score 1) 553

Nope, the parent is correct. The only difference between a struct and a class is the default access level of its members. Structs are public, classes are private.

It also has an effect on inheritance as well. A struct will inherit publicly by default,

struct A : B { };

is the same as

struct A : public B { };

Similarly for classes, but replace "public" with "private".

Both structs and classes are contiguous blocks of memory. The only cases where pointers come into play are when your member functions (methods) are declared as virtual.

Slashdot Top Deals

You will have many recoverable tape errors.