C++ Curiosities

Started by
43 comments, last by jflanglois 18 years, 1 month ago
Quote:Original post by NotAYakk
1> #define FORWARD_DECL
#include ...
#undef FORWARD_DECL
to get the forward declairations from a bunch of header files.

2> Primitive generic code tricks. Having a math library that works on doubles or floats or ints depending on what preprocessor tokens you define before #including it.


Another popular thing to do is:
/*************//* globals.h *//*************/#ifndef H_GLOBALS#define H_GLOBALS#undef MY_EXTERN#ifdef GLOBALS_ONCE#define MY_EXTERN#else#define MY_EXTERN extern#endifMY_EXTERN int g_int;MY_EXTERN double g_double;/* etc... */#endif/*************//* globals.c *//*************/#define GLOBALS_ONCE#include "globals.h"/**********//* main.c *//**********/#include "globals.h"int main() {    /* Use g_int, g_double, etc... */    return 0;}

Unless that's what you were meaning by your "forward declare" trick?
Advertisement
Quote:Original post by smitty1276
The "list of expressions to be evaluated" would look like valid c++ code (whereas the current incarnation does not). The for statement takes (expr list; bool expr; expr list), for example. My point with the initializers is that they were just kinda thrown in and have no relation at all to any other syntax in the C++ language. Assigning a value to a variable shouldn't look like a function call, unless that is what assigning a value to a variable looks like in the language.


It looks like a constructor call though. You do

MyClass object("data", 1, false);

So why not:

int number(7);

Seems pretty uniform to me...
Quote:Original post by smitty1276
The "list of expressions to be evaluated" would look like valid c++ code (whereas the current incarnation does not). The for statement takes (expr list; bool expr; expr list), for example. My point with the initializers is that they were just kinda thrown in and have no relation at all to any other syntax in the C++ language. Assigning a value to a variable shouldn't look like a function call, unless that is what assigning a value to a variable looks like in the language.

You arn't assigning a value to a variable. You are constructing a variable. And thats what constructing a variable looks like.
C++ is full of clumsy design choices. Consider the half-dozen meanings for the const keyword, "=0" used to designate pure virtual methods, virtual inheritance, the interaction of function overloading and template specialization.

C++ is a jack-of-all trades language that makes lots of simple things hard and takes way too long to learn well. Still, it's the only game in town if you want both high level programming constructs (object-oriented, generic programming) and low-level control (manual memory management, pointer fiddling, etc..)

-Alex
Quote:Original post by cypherx
C++ is a jack-of-all trades language that makes lots of simple things hard and takes way too long to learn well. Still, it's the only game in town if you want both high level programming constructs (object-oriented, generic programming) and low-level control (manual memory management, pointer fiddling, etc..)


So, basically, C++ let's you have your cake and eat it, too, so long as you don't mind a fresh-from-the-oven pan on your lap and that the frosting is laced with a triple dose of ex-lax.
Quote:Original post by Boder
flag ^= true;

This is more explicit, imo:
flag = ! flag;
C++ is such a poorly designed langauge because it is not a designed langauge.

C++ is such a great language because it is an evolved langauge, survivial of the fitest, or at least - survivial of that which happened to hitch a ride with that which was fit.

C++ is like it is for the same reason humans are like we are, because it was good enough to keep us surviving and evolving ... male nipples and all.

Almost all langauges with a better design have at least one fatal flaw that makes them unfit for some area of development ... hence the reason C++ remains the only true completely general purpose language ... while many other langauges are arriving which are better at larger and larger subsets of its domain (Java, C#, Python, ruby and many others from its line of offspring, plus dozens of langauges not directly decended from C: LISP, Eiffer, Haskell, ...)

But not one of the designers of those langauges ever said - how can I do EVERYTHING at least as well as C / C++, and then do most things better. They all said how can I do most things better than C / C++ and forget the rest.
Of all the questionable areas of standard C++ design, how the hell is initializer lists even being brought up? Seriously. If those complaints are the best you can come up with, then you need to learn a bit more of the language.

CM
Is C++ the biggest and most complex language?
No, Ada is the largest and most complex language.

This topic is closed to new replies.

Advertisement