Live data from Hacker News

Obscure C++ Features

madebyevan.com

11–20 of 58 posts

Re: Obscure C++ Features

#11

Dark font on dark background. Unreadable.

There are some advantages to the company firewall blocking style sheets.

Sorry, I know I'm drifting massively off topic now, but why on earth would any company adopt such a policy? It's not even as if CSS files can carry executable code (sure, they can reference such content, but then block that stuff instead of the style sheets themselves).

Re: Obscure C++ Features

#12
Re. the "redefining keywords" trick. I know this works with at least some versions of g++. However when I tried doing it in MSVC 2008 I ended up with link errors between the library object files (compiled without the redefinition trick) and the app executable that did use the trick. It looked like MSVC was encoding the visibility in the mangled method names.

Re: Obscure C++ Features

#13
post #8

The behavior of [] is from C -- it's not a bizarro C++ feature. The "redefining keywords" is the pre-processor. That's what it does. There isn't anything magic here. Strictly speaking it can be run entirely ahead of the C/C++ compiler, on any file you want. There's no requirement that it is C/C++ - you could use it on a python script (as long as you weren't using # comments anywhere :D )

There is somewhat of a requirement with the preprocessor - if you redefine a keyword and then include a standard library header it's considered undefined behavior. Maybe that's what the author meant.

Re: Obscure C++ Features

#14
C++ contains a syntactical shorthand for simultaneously declaring a variable and branching on its value.

    if (MouseEvent *mouse = dynamic_cast(event))
I think it is a complicated description and a complicated example for saying that the assignment operator (=) returns the value that was assigned.

Re: Obscure C++ Features

#15
post #8

The behavior of [] is from C -- it's not a bizarro C++ feature. The "redefining keywords" is the pre-processor. That's what it does. There isn't anything magic here. Strictly speaking it can be run entirely ahead of the C/C++ compiler, on any file you want. There's no requirement that it is C/C++ - you could use it on a python script (as long as you weren't using # comments anywhere :D )

>The behavior of [] is from C -- it's not a bizarro C++ feature.

I'd say that a feature of C++ is still a feature of C++ even if the same feature is in C.

Re: Obscure C++ Features

#16

C++ contains a syntactical shorthand for simultaneously declaring a variable and branching on its value. if (MouseEvent *mouse = dynamic_cast (event)) I think it is a complicated description and a complicated example for saying that the assignment operator (=) returns the value that was assigned.

for example int a = b = c = 0;

Re: Obscure C++ Features

#19
post #15
post #8

The behavior of [] is from C -- it's not a bizarro C++ feature. The "redefining keywords" is the pre-processor. That's what it does. There isn't anything magic here. Strictly speaking it can be run entirely ahead of the C/C++ compiler, on any file you want. There's no requirement that it is C/C++ - you could use it on a python script (as long as you weren't using # comments anywhere :D )

>The behavior of [] is from C -- it's not a bizarro C++ feature. I'd say that a feature of C++ is still a feature of C++ even if the same feature is in C.

The point was probably that it is not obscure; it's what you had to learn when using plain C in the first week.

Re: Obscure C++ Features

#20

C++ contains a syntactical shorthand for simultaneously declaring a variable and branching on its value. if (MouseEvent *mouse = dynamic_cast (event)) I think it is a complicated description and a complicated example for saying that the assignment operator (=) returns the value that was assigned.

The noteworthy bit is that declarations are valid in the conditional "expression" of if-statements and evaluate to the declared variable. It's imo not obvious that declarations are expressions sometimes.
Post reply on HN