News for hackers. Stuff that matters.
Re:C++ Modules Might Be Dead-On-Arrival by stochastic_monk on Monday January 28, 2019 @04:28AM (#19016168)
How would you write different code for different architectures or based on compilation flags without preprocessor directives? Rust has directives for specifying which version to compile, but C++ currently doesn’t. However, I find #if __AVX512BW__/#elif __AVX2__/#elif__SSE2__#else/#endif to be easy and flexible, allowing only a subset of code to vary by architecture. I also find that macros allow me to write much more concise, maintainable code.

It’s archaic and low level, but it’s also powerful and expressive. Replacing the CPP would probably just require a new language.

Re:C++ Modules Might Be Dead-On-Arrival by tambre on Monday January 28, 2019 @06:52AM (#19016750)
What about using `if constexpr`? Sure, there currently are no equivalent constant variables to use, but adding those should be very easy.
Re:C++ Modules Might Be Dead-On-Arrival by stochastic_monk on Monday January 28, 2019 @08:18AM (#19017179)
if constexpr only works for procedural code, not data members. (e.g., use __m128i v[4] for SSE2, __m256 v[2] for __AVX2__, etc.) It could be templated, as long as there was a compile-time method besides the CPP to get architectural information, so that would be a way (if much more verbose) forward.

That being said, if constexpr is great; iterating over either sparse or dense arrays with in Blaze without wrapping in two functions was mind-blowing when I discovered I could so easily.

Re:C++ Modules Might Be Dead-On-Arrival by gmueckl on Monday January 28, 2019 @10:11AM (#19017981)
That is why static if and version in D work very differently. Alexei Alexandescu criticized if constexpr in C++ for being a poor copy of static if that misses the point, but that was dismissed. But it is powerful enough to handle almost all cases of conditional compilation.
Re:C++ Modules Might Be Dead-On-Arrival by rini17 on Monday January 28, 2019 @12:15PM (#19019138)
Isn't C++ supposed to be object-oriented? Why you couldn't have specific class optimized for each architecture?
Re:C++ Modules Might Be Dead-On-Arrival by pjmlp on Monday January 28, 2019 @04:30AM (#19016177)
Like when one does proper C or C++ clean coding without pre-processor spaghetti, an implementation file for each architecture or OS specific coding.
Re:C++ Modules Might Be Dead-On-Arrival by MrStonedOne on Monday January 28, 2019 @05:26AM (#19016386)
So, copy and pasted code spread out everywhere rather than centralized?
Re:C++ Modules Might Be Dead-On-Arrival by pjmlp on Monday January 28, 2019 @07:14AM (#19016878)
Not at all, fine tuned in small functions or architecture specific headers.
Re:C++ Modules Might Be Dead-On-Arrival by banachtarski on Monday January 28, 2019 @05:39AM (#19016430)
Yes thank you. Not to mention that the parent comment neglects the fact that splitting out files just means you have to now worry about conditional inclusion or tighter coupling with your build system.
Re:C++ Modules Might Be Dead-On-Arrival by pjmlp on Monday January 28, 2019 @07:18AM (#19016895)
That approach has successfully turned a pile of spaghetti C pre-processor code into a managable secure server application deployed across Aix, HP-UX, Solaris, Linux and Windows NT/2000.

Yes it was tighly coupled with Make that took care of selecting the proper set of files to compile and link based on the platform.

The anti-module crowd seems to want to have it all, which to me is the same anti-exceptions and anti-RTTI crowd, and in that case modules are indeed dead-on-arrival.

Re:C++ Modules Might Be Dead-On-Arrival by frutiger on Monday January 28, 2019 @09:49AM (#19017766)
> That approach has successfully turned a pile of spaghetti C pre-processor code into a managable secure server application deployed across Aix, HP-UX, Solaris, Linux and Windows NT/2000.

I have also weitten and deployed what you’re denigrating as “preprocessor spaghetti code” across the above exact platforms, with a lot of success.

Perhaps we work(ed) at the same company.

Re:C++ Modules Might Be Dead-On-Arrival by wbkang on Monday January 28, 2019 @11:44AM (#19018879)
Couldn't you just link against a different version? e.g. mymodule-avx2.o vs mymodule-avx.o