Le 12/08/2016 à 18:59, Richard a écrit :
> [Please do not mail me a copy of your followup]
>
>
ja...@jacob.remcomp.fr spake the secret code
> <nok3sq$dkb$
1...@dont-email.me> thusly:
>
>> Le 12/08/2016 à 10:08, Öö Tiib a écrit :
>>> I think that C++11 should also print X!. Where you took that from?
>>
>> Chandler-Carruth
>> Lead developper of the "clang" compiler project. And before you write "I
>> think that..." can you compile that?
>
> Chandler Carruth is the lead developer of the C++ tools team at
> google. I don't think clang itself can be considered to have a
> single lead developer. Different people take responsibility for
> different areas. See
> <
https://github.com/llvm-mirror/llvm/blob/master/CODE_OWNERS.TXT>
> <
https://github.com/llvm-mirror/clang/blob/master/CODE_OWNERS.TXT>
> <
https://github.com/llvm-mirror/clang-tools-extra/blob/master/CODE_OWNERS.TXT>
> etc.
>
> Getting back to the example code, my takeaway is two-fold:
>
> 1) It's been a well known problem that overloading functions for a pointer
> type and an integer type leads to surprises.
Yes. And what about fixing THOSE problems BEFORE adding new features?
> Is NULL an integer or is
> it a pointer?
Zero is zero, and a zero pointer points to the first available memory
location. It is useful to make this (easy to test) location a convention
for meaning:
1) This pointer has no value yet, or
2) its value was destroyed, or
3) it means "not found", when you call a search function.
> It depends on the implementation.
Maybe there are more use cases but let's keep those three use cases.
Then, the standard should give SIMPLE rules what is NULL in which context.
Problem is, that C++ has becomed plagued with ambiguity, since automatic
generated code is issued on behalf of the programmer.
This feature can be used, but also abused, it is a matter of measure.
The golden rule is that the language should be able to be parsed by a
qualified reader in a short period of time. Rules should be easy to
grasp and their number should be reduced to a minimum.
There are too many interacting constructs that come to be added to the
language, complexifying even more a complex situation. Let's STOP.
I have a solution:
Let's make the compiler itself PROGRAMMABLE. Let's design a simpler
language but with a programmable compiler where it is easy to write new
constructs without complexifying the whole language.
Conceptually then, a compiler is a source of syntactic and grammatical
EVENTS.
The automata starts in the null state, and its state is governed by the
text written in the source code.
A series of events is generated by the compiler. For instance:
Start struct declaration
End struct declaration
Constructors / Destructors belong here.
Start statement
End Statement
A profiler could subscribe to those events, and generate code to measure
the time the processor spent executing that statement
A debugger could generate code to be passed control if doing single
stepping.
Start function/method definition
End function/method definition
And many other events the compiler user can meaningfully use in the
application they are writing. Lambdas? Of course. If you need them
you use one of the language libraries around. Those libraries subscribe
to compiler events and generate code for you to do lamndas, and many
other quite interesting software constructs.
The core language stays fixed, the text is portable. Libraries are less
portable, and sophisticated software constructs have a price. But it is
again the user that decides if he wants the extra complexity of writing
and mainting that kind of code. New features are introduced individually
in some installations and people gain experience using them.
After some years of usage and if the authors want it, libraries would
enter the Boost library and become semi-official, with lambdas, regular
expressions, closures, what have you. This language libraries would hang
their code in specific events generated by the compiler and would write
either:
Core language to be compiled, inserted into the text stream at the call
point
or
Assembler to be inserted at the exact point of the event firing into the
object code stream.
Maybe more on this later
This is one of the
> reasons why nullptr/nullptr_t was added to the language. Overloading
> on both of these types as the only difference in the signature is
> going to be surprising unless you static_cast<> appropriately.
>
Of course. It is impossible for the automata to disambiguate the two
meanings since it has no notion of "meaning". It is the programmer
that gives any meaning here, and in this case it could be required.
> 2) Single argument constructors that allow implicit conversion between
> types is also a well known problem that leads to surprises. All the
> C++ "lint" like tools I know of report warnings or errors for such
> constructors and advise you to make the constructor explicit.
>
> This code wouldn't lead to such surprising results if it had been
> written to avoid these well known areas of surprise.
>