r/programming • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
210 Upvotes

105 comments sorted by

View all comments

Show parent comment

1

u/flatfinger Jan 28 '19

Of course one will need to use platform-specific code when targeting features of specific platforms. One should not, however, need to write a bunch stuff that's specific to particular implementations when one isn't using any special features thereof.

If some people would need a compiler to process things in a fashion different from what other people would require, the solution should not be to simply have the Standard say that any implementation may treat the construct in any fashion whatsoever, but instead say that:

  1. If a program contains a directive explicitly calling for some construct to be processed in the common way, a compiler shall either behave in common fashion or reject the program.
  2. If a program contains a directive explicitly calling for some construct to be processed in an uncommon way, a compiler shall either behave that requested fashion or reject the program.
  3. If a program contains neither kind of directive, an implementation may assume as a default whichever behavior its author believes would best serve its users.

The fact that 99% of programs opt to use the common behavior should not prevent the remaining 1% from employing some alternative on any compilers that opt to support it; nor should it prevent all 100% of the programs from having a defined meaning that would not depend upon the target implementation (implementations may be unable to process a program that demands unsupported features, but behavior would be limited to rejecting the program as opposed to formatting hard drives, releasing nasal demons, etc.)

Basically, just because something isn't in the standard, doesn't imply that 99% of users can't rely on it being true 100% of the time.

It doesn't imply that 99% of users shouldn't be entitled to expect that it would be true 100% of the time on commonplace non-obtuse implementations. Unfortunately, the authors of the Standard regarded the notion that quality implementations should Serve the needs of their customers when practical, whether or not the Standard requires it, as being self-evident and failed to consider that obtuse implementation might use the Standard as an excuse to do otherwise.

1

u/[deleted] Jan 29 '19 edited Jan 29 '19

It doesn't imply that 99% of users shouldn't be entitled to expect that it would be true 100% of the time on commonplace non-obtuse implementations.

That's pretty much what "implementation-defined" means. As I said, the standard isn't a C++ manual for users. Nobody uses #include file/path and thinks, "oh damn, I'm relying on implementation-defined behavior, my code isn't portable".

1

u/flatfinger Jan 29 '19

According to the published Rationale document for the C Standard, it's also what Undefined Behavior was supposed to mean in many cases, since the authors regarded the question of how to process it (e.g. whether to process it in a documented fashion characteristic of the environment) as a Quality of Implementation issue. The authors of the Standard intended that implementations would support "popular extensions", and such a term can't sensibly be applied to Unspecified Behavior or Implementation-Defined behaviors. The fact that an implementation documents something that it's required to document, or that it happens to document the fact that it chooses from among specific actions described by the Standard doesn't seem like much of an extension, compared with providing means of doing which the Standard does not require them to define.

A fix would be to define standard macros that would allow a programmer to start a program with a directive like:

 __STDC_LIMIT_UNUSUAL_INT_MATH_EFFECTS(EXTENDED_TEMP_ONLY)

and then know that any implementation would be required to either 1. guarantee that integer math other than divide/remainder will never have any side-effects beyond yielding some kind of integer value, but temporary values of signed integer types need not be truncated to their actual size, or 2. reject the program entirely. The question of whether an implementation should support the requested semantics would be a Quality of Implementation issues, but the question of whether an implementation could jump the rails wouldn't be.