Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror

Slashdot videos: Now with more Slashdot!

  • View

  • Discuss

  • Share

We've improved Slashdot's video section; now you can view our video interviews, product close-ups and site visits with all the usual Slashdot options to comment, share, etc. No more walled garden! It's a work in progress -- we hope you'll check it out (Learn more about the recent updates).

×

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

by bstamour (#41819371) Attached to: The IDE As a Bad Programming Language Enabler

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

by bstamour (#40590927) Attached to: Objective-C Overtakes C++, But C Is Number One

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

by bstamour (#40521125) Attached to: What's To Love About C?
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:So it works the way Stallman envisioned? (Score 1) 191

by bstamour (#34456812) Attached to: Paid Developers Power the Linux Kernel
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

by bstamour (#33911340) Attached to: Bjarne Stroustrup Reflects On 25 Years of C++
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.

User hostile.

Working...