Announcement

Collapse
No announcement yet.

Coroutines & Modules Added For C++20

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • carewolf
    replied
    Originally posted by coder View Post
    I still think you don't understand what a "use case" is.


    To invoke a default constructor/destructor/copy-constructor/assignment operator requires the compiler to instantiate them, for which it needs the full details of the members.
    Yes, more specifically, it needs to allocate space first before running the constructor on that space. Which is why factory methods can work-around the issue by calling the constructor from a place where its full definition is known. Or you use the d-pointer/pimpl design and just have the member be a single pointer, and then let the constructor allocate as much space as it needs in the private pointer, but that comes at the cost of an extra indirection, but has the advantage of being possible to expand and change without breaking the ABI, thus can be used for upgradable libraries.

    Leave a comment:


  • bountykiller
    replied
    Originally posted by cj.wijtmans View Post

    so you cant import a module? the compiler should be able to use the same information that a header contains (except for macros and certain templates but those shouldnt exist in C++ anyway)
    Yes, it's almost that.
    Modules are imported almost like headers are, but unlike headers they don't ship macros.

    Leave a comment:


  • coder
    replied
    Originally posted by atomsymbol
    I still think the requirement of knowing sizeof(T) and alignof(T)
    I still think you don't understand what a "use case" is.

    Originally posted by atomsymbol
    Invoking T's default constructor, destructor, assignment operator, or copy-constructor: These are plain function calls, unless inlining. Default constructor/etc are automatically marked as inline by current compilers - a current-compiler-specific feature.
    To invoke a default constructor/destructor/copy-constructor/assignment operator requires the compiler to instantiate them, for which it needs the full details of the members.

    Leave a comment:


  • dwagner
    replied
    Regarding modules: Apart from those who just want modules to improve build speeds, there are also those who dream of shipping binary "modules" rather than libraries + source header files because they dislike open source as a business model, and hope that "modules" will be easier to ship without lots of source code in lengthy header files. Only time will tell how often this feature will be used an abused. And whether compiler makers will succeed to let modules actually work faster and more flexible than "pre-compiled headers".

    Leave a comment:


  • dwagner
    replied
    Originally posted by atomsymbol
    [I]C++ forces the programmer to define types of fields of a struct/class before the struct/class is defined. This is putting a very strict constraint on the ordering of struct data types in the source code. You cannot call a virtual method (defined elsewhere !!!) before the struct definition has seen the definition of the types of its fields, while obviously the knowledge of fields is immaterial to the virtual method call.
    You are free to define a base class devoid of data members that just contains virtual member function definitions, and call them just fine, even without knowledge of the fields that some derived class (that you actually have a reference to and call the member function of) added to the base class. So I don't see your problem.

    Leave a comment:


  • pal666
    replied
    Originally posted by atomsymbol
    Exactly.
    so, since compiler doesn't need fileds, you are free to not give him fields. give him methods and put fields somewhere else (like in derived class for virtual case)

    Leave a comment:


  • pal666
    replied
    Originally posted by atomsymbol
    An imaginary compiler could postpone global&static&stack allocations to link time
    stack allocation is code generation. c++(like c) is designed for separate compilation to keep resource usage tractable, lto is just possible optimization
    Originally posted by atomsymbol
    Passing T by value: This case can be reduced to allocation of sizeof(T) bytes followed by invocation of the copy-constructor.
    so how do you know sizeof(T) without seeing full definition of T?
    Originally posted by atomsymbol
    Invoking T's default constructor, destructor, assignment operator, or copy-constructor: These are plain function calls, unless inlining.
    i.e. unless by default. so you are trying to make all c++ programs slower. and btw, special member functions are not generated by compiler unless used. generation without use will make compilation slower
    Originally posted by atomsymbol
    Default constructor/etc are automatically marked as inline by current compilers - a current-compiler-specific feature.
    there is nothing compiler-specific in knowing code which it generates
    Originally posted by atomsymbol
    new T(): This is a call to function "T* new_T()" created by the compiler in the single .cc file that can see the field types and thus knows sizeof(T).
    no, this is a call to https://en.cppreference.com/w/cpp/me...w/operator_new followed by call to constructor. what you are showing is factory function, you can do it yourself. compiler can't do it because it doesn't know you will be using operator new at all and which one and with which constructor (while compiling unit with class definition)

    Leave a comment:


  • pal666
    replied
    Originally posted by atomsymbol
    True, although the PImpl pattern require the programmer to define an extra class which would be unnecessary in some cases if the language&compiler allowed usage of classes (method calls) without knowledge of field types.
    it already allows that. just declare your method externally (make it free function).
    Originally posted by atomsymbol
    Abstract interfaces still require #include directives due to instantiation via operator new of interface implementations, which is unnecessary because the invoking the constructor+operator_new does not need the caller to know the representation of class's fields.
    invoking operator new does indeed need to specify size, which is not known before full definition of class is known. another ridiculous example of high demands due to high stupidity on your part. btw, this issue is trivially sidestepped by declaring factory function, but people who are not smart enough to do that are left only with choice of making stupid claims
    Last edited by pal666; 25 February 2019, 06:51 PM.

    Leave a comment:


  • pal666
    replied
    Originally posted by kpedersen View Post
    Whilst I am not a fan of the modules idea (I fear it will end up turning C++ into a Javascript-like dependency cluster-fsck)
    you are confusing c++ modules with something else

    Leave a comment:


  • pal666
    replied
    Originally posted by atomsymbol
    Why should it matter what you think about the idea of superfluous C++ #includes/import to me? Or do you happen to be implementing a compiler?
    i didn't share any thoughts on "of superfluous C++ #includes/import" with you. i only mentioned that your idea of compiler requiring fields declaration to call virtual function is idiotic, compiler doesn't require that

    Leave a comment:

Working...
X