Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Drastic Actions posted:

Hopefully now more people can get articles in ZDNet with the advance hacking techniques I’ve provided.

Look out Tavis, there's a new sheriff in town.

Adbot
ADBOT LOVES YOU

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

SupSuper posted:

They still suck for compile time though.

Yeah the compiler still has to parse the code, instantiate it, maybe inline it etc. Trivial functions like std::move and std::forward that don't actually do anything (they're just specializations of the static_cast operator) have a massive impact on compilation time: every time you compile, the compiler has to do all the instantiation, optimization etc. work just to reach the same conclusion every time (they just return their argument and they're effectively no-ops). I wonder if there are any compilers that precompile templates in headers to actual executable code

hackbunny fucked around with this message at 02:28 on Nov 28, 2021

fritz
Jul 26, 2003

Mooey Cow posted:

Not really. Maybe 20 years ago, but if you need code to work over multiple types, they generally result in identical code to handwritten specializations. Sometimes smaller, since unused template functions and methods are not even emitted (although unused handwritten code could also be removed at linktime). It's also usually possible to separate out code that doesn't depend on the type to avoid unnecessary code duplication within functions, but you would also have to do that if you wrote your functions by hand and wanted to minimize size.

This has not been my recent experience. (template-heavy code --> boss asks to get working on embedded platform --> oh god)

Volte
Oct 4, 2004

woosh woosh
I tried to use the PEGTL (template based PEG grammar parser) library for a parser recently and the grammar file took upwards of 15 seconds to compile just for what amounted to basically a stub of the full grammar, so yeah, templates for basic generic programming are one thing, but using them for more complex compile-time programming is definitely a huge trade off.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
PEGTL also generates absurdly huge object files.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

HappyHippo posted:

I don't think templates being turing complete affects the parsing. Many turing complete languages are parseable after all. The issue (I believe) is there are ambiguities that can only be resolved if you know what kinds of things the tokens involved are (such as types or variables), eg:
code:
a < b > c;
or
code:
T *p;

That’s actually exactly why parsing is affected by the theoretical complexity of things like templates and constexpr. When you have a construct like A<E>::x, parsing sometimes depends on the kind of declaration named by x. If A<E> is a dependent specialization, then that’s unknowable and C++ has various rules for picking a presumptive kind (and overriding it when necessary) so that parsing can continue; but if it’s non-dependent, C++ says that parsing uses the actual lookup, which means you have to resolve the specialization, which means you have to resolve E down to a concrete type/value, which can require instantiating other templates or calling constexpr functions or lots of other stuff.

If you’re willing to form an ambiguous parse tree then that’s quite different, but the ambiguity can accumulate pretty quickly because of things like T*x.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
All this stuff sounds like a complete nightmare. Is writing a c++ compiler a constant series of Herculean problems or is it all more tractable than it sounds?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dr Monkeysee posted:

All this stuff sounds like a complete nightmare. Is writing a c++ compiler a constant series of Herculean problems or is it all more tractable than it sounds?

Vendors argue against new features because they’re hard to add.

So.. yeah; giant barely tractable project if you want to support the full thing.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I think I heard that for C++17 or C++20 the standards committee gave up on telling vendors what they should add and just started picking out new features that the vendors had already added.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
It's a huge language with a lot of complexity and corner cases even before you start considering the massive set of vendor extensions. You try to get the basic concepts right in the compiler design so that you're not fighting yourself too much, and hopefully that carries you through well enough so that you only have a small (but endless) trickle of (1) things you got subtly wrong and (2) things that you gave up on so you could ship and always meant to get back to. The parsing thing really isn't a problem for the implementation because the parser generally has a handle on something that knows how to do semantic analysis anyway; similarly, formal decidability is not particularly important because formally almost any conceivable language processor is only implementing a conservative subset of the formal language because of implementation limits, either statically (e.g. due to exponential worst-case behavior in Hindley-Milner unification) or dynamically (e.g. due to finite memory).

But what the C++ committee did was just to start requiring implementation experience before it would consider core language proposals, which is a good idea in any language — it's quite easy for someone who's just writing a design document to overlook even more complexities and corner cases and odd interactions than you actually intended in your design. This being C++, of course, the committee only learned this lesson after repeatedly screwing up, including in ways that are sometimes now baked into the ABI.

rjmccall fucked around with this message at 09:05 on Mar 18, 2019

Ola
Jul 19, 2004

What I don't get is why they add so much stuff that users could implement themselves. I was at a talk with Stroustrup himself, he mentioned they had added support for binary literals. Then the people who wanted the binary literals found out it was quite difficult (!) to read big numbers in binary, but easier with spacing, so you can group your ones and zeroes with spaces. Why not just tell them to write their own classes to parse input and output numbers? Why should every one else in the chain have to worry about it?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Ola posted:

What I don't get is why they add so much stuff that users could implement themselves. I was at a talk with Stroustrup himself, he mentioned they had added support for binary literals. Then the people who wanted the binary literals found out it was quite difficult (!) to read big numbers in binary, but easier with spacing, so you can group your ones and zeroes with spaces. Why not just tell them to write their own classes to parse input and output numbers? Why should every one else in the chain have to worry about it?

So you're saying that if someone wants conveniences like binary literals and optional digit grouping in numeric literals (both of which are found in various mainstream languages), they should have to modify their compiler to get it? That doesn't strike me as reasonable.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
re: the ambiguity of MyTemplate<T>::x * y meaning either a pointer declaration or a multiplication operation: is there a way you can write that and make it explicit that you mean it to mean one thing or the other? Like can I explicitly invoke operator*()? I guess if you want to make sure it can only be a pointer declaration there might be a way to force that by using the typename keyword?

After all, this ambiguity only arises because it so happens that the * character is used for two different purposes

Ola
Jul 19, 2004

Hammerite posted:

So you're saying that if someone wants conveniences like binary literals and optional digit grouping in numeric literals (both of which are found in various mainstream languages), they should have to modify their compiler to get it? That doesn't strike me as reasonable.

Well if person A won't do it for person A's convenience, person B has to do it for person A's convenience. Is that more reasonable? If there is a big demand for it, performance boosts, sure. But the way Stroustrup explained it, it was a pretty niche group and they didn't have great reasons for it. And it's perhaps not the greatest example. Anyway, Stroustrup seemed like a guy with serious mass email flame war PTSD.

Xarn
Jun 26, 2015

Ola posted:

What I don't get is why they add so much stuff that users could implement themselves. I was at a talk with Stroustrup himself, he mentioned they had added support for binary literals. Then the people who wanted the binary literals found out it was quite difficult (!) to read big numbers in binary, but easier with spacing, so you can group your ones and zeroes with spaces. Why not just tell them to write their own classes to parse input and output numbers? Why should every one else in the chain have to worry about it?

:thunk:

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Ola posted:

Well if person A won't do it for person A's convenience, person B has to do it for person A's convenience. Is that more reasonable? If there is a big demand for it, performance boosts, sure. But the way Stroustrup explained it, it was a pretty niche group and they didn't have great reasons for it. And it's perhaps not the greatest example. Anyway, Stroustrup seemed like a guy with serious mass email flame war PTSD.
When person A is everyone who might use the feature, including lots of people with no experience with, knowledge of, or access to compiler development, and person B is the people who do have those things, and in fact it is their "job" (sometimes literally, sometimes not depending on the OSS-ness of the compiler) to implement things for the "convenince" of person A, then yes, that's reasonable, assuming person C (the spec committee) can properly balance the difficulty of implementing the feature, the size of the person A group, and the size of all potential person A groups that don't get what they want because resources are spent on this particular group of persons A.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
What really bothers me is that Stroustrup's book uses a non-monospaced font for code examples.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Binary literals and digit spacing with _ are weird examples because they're straightforward to design and implement and have obvious benefits for certain kinds of programming. It is extremely typical of Stroustrup to wring his hands over that while passionately pushing for every complex and cross-cutting expressivity feature under the sun because without them C++ will fade and pass into the west.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I don't have the galaxy brain required to do C++, but with constexpr it should be possible to implement compile-time binary literals as a plain library without any need for compiler work, no?

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
What would be useful is if bitfields had a guaranteed order. Maybe the do in c++ idk.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

NihilCredo posted:

I don't have the galaxy brain required to do C++, but with constexpr it should be possible to implement compile-time binary literals as a plain library without any need for compiler work, no?

It is possible (I implemented hex literals for a custom bit-array class some time ago), but it is cumbersome. Also, binary literals can be parsed almost trivially by the tokenizer, using templates is much more expensive and slows down compilation.

fritz
Jul 26, 2003

Dr Monkeysee posted:

Is writing a c++ compiler a constant series of Herculean problems

Well, considering the language makes the Augean stables look clean ....

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



dougdrums posted:

What really bothers me is that Stroustrup's book uses a non-monospaced font for code examples.

Look we all already knew he was a monster this is just gilding the lily

1337JiveTurkey
Feb 17, 2005

Some of Stroustrup's choices in The Design and Implementation of C++ (I think that was the name) regarding syntax just drove me up the wall because it's like "What if you want to run C code through your C++ compiler?" It's just not a sensible design choice for a new language.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It's almost like C++ was designed as an extension to C rather than a new language.

xtal
Jan 9, 2011

by Fluffdaddy
I don't write C or C++ but isn't one of its most important features that you can drop in C code transparently?

xtal fucked around with this message at 22:30 on Mar 18, 2019

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
People like to go "well actually C++ isn't a perfect superset of C and therefore...", but yes, being able to seamlessly mix in C and compile most C code as C++ is a very useful feature.

OddObserver
Apr 3, 2009

Plorkyeran posted:

People like to go "well actually C++ isn't a perfect superset of C and therefore...", but yes, being able to seamlessly mix in C and compile most C code as C++ is a very useful feature.

I think you might be understating the difference to pre-ANSI C, though.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The biggest differences between early-release and ANSI C — function prototypes, struct member namespacing, a less ridiculous basic type system — were already things that people acknowledged as bad, so fixing them in C++ was fine. extern "C" is really the biggest remaining difference. I'm surprised sometimes that C++ didn't just make normal global functions non-overloadable so that they could be extern "C" by default and headers would've just worked. I suppose that would've interfered with some of the language-linkage pipe dreams.

Spatial
Nov 15, 2007

Why would anyone want binary literals, on a binary computer system? Madness I tell you

Doom Mathematic
Sep 2, 2008

Spatial posted:

Why would anyone want binary literals, on a binary computer system? Madness I tell you

Or a Boolean data type, come to that?

nielsm
Jun 1, 2009



Spatial posted:

Why would anyone want binary literals, on a binary computer system? Madness I tell you

Octal is all you'll ever need.

Ola
Jul 19, 2004

Spatial posted:

Why would anyone want binary literals, on a binary computer system? Madness I tell you

Not being able to write numbers as ones and zeroes on a computer that uses ones and zeroes is why the world was unable to do anything at all with computers until the launch of C++14.

JawnV6
Jul 4, 2004

So hot ...

nielsm posted:

Octal is all you'll ever need.

Folks write a shitload of octal constants. Like they might even be a plurality in some programs.

Falcorum
Oct 21, 2010

xtal posted:

I don't write C or C++ but isn't one of its most important features that you can drop in C code transparently?

No but also yes.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Falcorum posted:

No but also yes.

To clarify, good C isn't necessarily good C++. C++ has OOP (abstraction/polymorphism/etc), like smart pointers and containers etc. Dropping in C unmolested is generally not good practice - I mean it's done and there are use cases for it, and it'll generally work, but it's gross.

The C compatibility is useful from a historical standpoint to explain how C++ became commonly used as it was easy for C shops to convert and start using C++ features incrementally.

Volte
Oct 4, 2004

woosh woosh
C compatibility is used all the time. C is the lingua franca of cross-language bindings, even for C++. If your C header file has any inline functions in it, you better hope your C++ compiler can compile them.

Ola
Jul 19, 2004

Bruegels Fuckbooks posted:

To clarify, good C isn't necessarily good C++. C++ has OOP (abstraction/polymorphism/etc), like smart pointers and containers etc. Dropping in C unmolested is generally not good practice - I mean it's done and there are use cases for it, and it'll generally work, but it's gross.

The C compatibility is useful from a historical standpoint to explain how C++ became commonly used as it was easy for C shops to convert and start using C++ features incrementally.

You make it sound as if "C shops" are small and reluctant mom&pop operations skeptical to the C++ skyscrapers over yonder. But it's good for perspective to remember that the whole world of business and science was running on C and that C++ was made to make C better. "Dropping in C unmolested" was a matter of saving millions or billions of dollars in massive finance projects, space projects etc etc.

Just imagine how many times this head has been scratched:

NtotheTC
Dec 31, 2007


Ola posted:

Just imagine how many times this head has been scratched:



Enough to wear away most of his hair

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Hah I remember inlining ASM into Turbo Pascal. Now that was a feature!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply