Why does C++ need language modifications to be “managed”?

前端 未结 11 1953
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 20:18

Why can\'t a compiler be written that manages what needs to be managed in C++ code (i.e. to make it \"CLR compatible\")?

Maybe with some compromise, li

11条回答
  •  走了就别回头了
    2021-02-14 20:34

    first thing to consider is every thing that makes c++ "fast" will disappear. a full garbage collection system in c++ is next to impossible. because c++ you can have pointer nearly anywhere in the code. runtime type information becomes costly if not directly built into the langauge system it self. you can take advantage of true native performance. template will dissappear. true pointers will dissapear. direct access to memory is gone.

    list of things that would have to be enforced

    1. no direct pointers(pointers will get replace with complex refernces)
    2. templates (generics pay for preformance)
    3. simple c-style arrays (will get wrapped with array structures)
    4. programmer no longer has control of whether data is on the stack or
    the heap.
    5. garbage collection will be enforced(this will cause the most changes to the syntax)
    6. runtime type data will get added extensively to the code.
    (larger code size)
    7.  inlining will become more difficult for the compiler
    (no more inline key word)
    8. no more inline assembly.
    9. the new langauge by now will become incompatible c code.(unless you go through hoops) 
    

提交回复
热议问题