Go Down

Topic: About low-level programming... (Read 7134 times) previous topic - next topic



I especially liked this bit about C++:
When it's 3 A.M., and you've been debugging for 12 hours,
and you encounter a virtual static friend protected volatile
templated function pointer, you want to go into hibernation and
awake as a werewolf and then find the people who wrote the
C++ standard and bring ruin to the things that they love


A Michigan man!  Very funny stuff, thanks for the link.  I also liked

...and ancient blood rituals that Bjarne Stroustrup performed at Stonehenge.


A Michigan man!  Very funny stuff, thanks for the link.  I also liked

...and ancient blood rituals that Bjarne Stroustrup performed at Stonehenge.

I've been told that on my side of the pond his name is pronounced Barney Shoestrap.  ;)




I like C a lot.  It took years to decide to devote time to learn it, because I had been told when I was young that it was a weird and difficult language.  Now, I think it's elegant and straightforward.

But C++?  Man... I can't help but feel it just wasn't very well thought out.  Having classes and overloading is nice though...


Learn the standard template library (STL) and you'll fall in love with it. :)

It lets you do linked lists, vectors, maps, etc. really elegantly. And it saves you having to re-invent a linked-list method every time you come up with a new structure.

Plus, it has a *cough* string class.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


My needs often dictates how much I remember. I learned C++ several times but didn't retain everything or half what I learned. If you ask me what implicit copy constructor does in an exam, I'll tell you the right thing only because I looked it up a week ago. But friends, and templates? I don't really remember nor did I find use yet. Programming arduino limits the use of lots of features in C++ that I would have use programming a PC.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


But friends, and templates? I don't really remember nor did I find use yet.

I can somewhat recommend this Free Online Class on "C++ for C programmers."

I mean, there are significant problems with this class.  The prof talks too slow, and will spend 10 minutes explaining how "swap" works, only to have a HW assignment along the lines of "implement an AI that uses a generalized undirected graph datastructure with colored edge weights and Djiksta's algorithm to play the game of Hex."  (did I say "along the lines of"?  I meant "exactly."  Grr.)
And apparently some of what he advocates is considered controversial (operator overloading?)

But on the other hand, he dives right into the things that are different than C and how and why they're useful.  "templates" got talked about in the first set of lectures (thus the annoying diversion into the history of "swap".)  Friends and inheritance and virtual functions are in there (whereas they tend to be either left as "advanced" topics or taken for granted in many books/classes that teach an OOP from the ground up.)  IOsteams properly introduced as an operator-overloaded shift...

I'm flunking.   But I'm getting a significant amount out of the class, and a lot of things have become much clearer to me...
I can live with that!



virtual static friend protected volatile templated function pointer,

I found that very funny, it is bar sport.
Having read subsequent posts im now thinking such a thing exists.


Well, every word is a C++ concept; I'm not quite sure whether they make sense all strung together.

OTOH, I've had to use tools to create/interpret C definitions for functions of stuff that returns (pointers to) arrays of function pointers, for real, and I'm pretty sure you can attach additional C++ concepts to those to make them even less intelligible...


I can understand function pointer and static friend. But what does it mean by virtual static friend then? If a function is static, can it be overridden by a class that inherits from the base class?

Where does volatile apply? The pointer is changing value so don't optimize code that accesses its value in a register or memory?

Templated is beyond my understanding. I don't use templates yet.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


I did not try to make sense of it.
Function pointer was enough to put me off.


But how would you write plugin frameworks without function pointers?  :)  They're the same as variable pointers, just referring to functions that can be called by address instead of values that can be read by address.  Simple!

Templates?  No idea.  When I hear "template", I think of a stripped source file that can be customized to do something convenient without having to write it all from scratch.  I assume the C++ concept is vaguely related, although not necessarily.  "Overloading" sounds like something that would cause a compiler error, but it's actually a useful (if not sometimes obfuscating) feature, so who knows?

I'm a huge fan of clean, readable, intelligible code.  Anything that makes code harder to comprehend is detrimental, although occasionally necessary.  While I also like to write efficient code, if I have to pick between clarity and performance, it becomes an internal struggle weighted mostly by the number of times the given code will be run in a loop, or whether there will likely be events depending on its completion in the shortest possible time.

C++ just reeks of a language developed with all the latest theory and patterns, while being early enough that it didn't have the benefit of learning from the dubious attempts by many other well-established languages trying to achieve similar goals.  (I could be way off -- I'm not a comp-sci history buff.)  It's almost like you can see the parts where C++ departs from C syntax the same way you can tell when somebody added a room to a house 20 years after it was constructed.  This side?  Elegant, logical, well-planned and solid.  This side?  The contractor forgot to let the foundation settle, and the AC outlets all tap off the light switch in the adjacent bathroom, but the paint's fresh and vibrant!

Then there's PHP, which has absolutely no excuse.  Sheesh.  Is this perl or C?  Nobody knows.


Templates are essentially a mechanism for making decisions at compile time that is much more powerful than preprocessor macros, and more HLL-aware than the usual assembler macros.
So you can do something like:
Code: [Select]
template <typename swappable_t>
void swap(swappable_t *a, swappable_t *b)
   swappable_t temp;
   temp = *a;
   *b = *a;
   *b = temp;

And then if you have
Code: [Select]

int a, b;
student_t s1, s2;
     swap(&a, &b);
     swap(&s1, &s2);

The first statement will cause a version of swap that works on ints to be compiled, and the second will cause a version of swap that works on students to be compiled.
I guess it can get a lot more complicated than that; templates are apparently a turing-complete programming language all by themselves.  So they can do anything if you're willing to be obscure enough.  (and thus, back to the sort of complaints in the original article!)


C is known to be dangerous, so most go in expecting trouble. If they don't find it? GREAT!!! But at least YOU WERE WARNED.

C++ was formed by a committee to make C safe. So poor blighters go in expecting a great experience and get devoured by beasts that never have been described. And if one survives, one has know way of knowing how one survived,it's as if all memories were erased.

Go Up