last day (19 days later) » 

4:40 AM
2
A: Covariant return type with non-pointer/reference return type

David Rodríguez - dribeasCovariant value return types cannot be implemented. The problem is that it is the responsibility of the caller to allocate space in the stack for the returned object and the amount of space required for a covariant value return would be unknown at compile time. This works seamlessly with pointer...

 
There are different alternatives... dynamically create the object and return a smart pointer to the base, create a wrapper in the lines of boost::any...
 
"This works seamlessly with pointers/references as the returned object is the pointer or reference" do you assume that the representation of different types of pointers are compatible?
 
@curiousguy: I am assuming that pointers to different types in a hierarchy are compatible. If that was the reason for the downvote, I urge you to provide a single architecture where that was not the case, or a hypothetical reason that could make such an architecture viable.
 
Do you assume that a Derived* object can be reinterpreted as Base*?
 
@curiousguy: No, and in most cases it cannot, I only assume that the size of a pointer to Base and a pointer to Derived are of the same size. For examples where Derived* cannot be reinterpreted as Base* consider any case of multiple inheritance where only the first base can be aligned, or even single inheritance if the base has no virtual functions.
 
4:40 AM
@DavidRodríguez-dribeas If two types have different representation, how does it matter that they have the same size known size?
 
@curiousguy: The two types don't have different representation, both of them are a pointer, with potentially different value. Why does it matter? Because the calling convention requires an agreement between caller and callee as to where the returned object is and how big it is. The common convention is that the caller reserves the space, and the callee just fills the data in. Now with pointers, the callee can write the pointer in the location (which can actually be a pointer to base and let the caller implicitly cast down when the call is performed though a reference to derived)
@curiousguy: ... now, if the language allowed to return a covariant type by value, how would the caller know how much memory it needed to allocate (in most current calling conventions the caller reserves the space) without knowing the actual final overrider? If the calling convention was changed so that the callee reserved the space, how would the caller know how much space was reserved by the callee (short of runtime type information)? I don't know how familiar you are with what really goes under the hood, but try to figure out a way to do that and I will be more than happy to hear about it.
 
@DavidRodríguez-dribeas "let the caller implicitly cast down when the call is performed though a reference to derived" No, it cannot in general; at least not from a virtual base. "I don't know how familiar you are with what really goes under the hood," I believe I am. "but try to figure out a way to do that and I will be more than happy to hear about it." The exact same way covariant pointers work.
@GManNickG I have flagged your offensive comment. I am tried to explain you covariant return, you have dismissed my explanations, you have been rude in the chat, but now I have enough with your arrogant behaviour. "but he refuses to understand that it doesn't work very cleanly in practice." the problem is that you do not understand the workings of covariant return, I have pointed that to you, and you are not able to admit your failings. From now on, I will apply a "zero tolerance" to your arrogant insulting remarks. You have been warned.
@DavidRodríguez-dribeas "let the caller implicitly cast down when the call is performed though a reference to derived" So, you are now implying that it does not matter at all that the sizeof is the same. So, I consider my downvote accepted.
 
@curiousguy: I am saying that it cannot be done with values, and yes, before that I said that size matters, and the reason is that the calling convention requires an agreement at compile time between caller and callee, and that agreement could not be reached if the returned object was a covariant value.
 
I know what a calling convention is.
You are saying that the callee really returns a pointer to Base, not to Derived.
So it is not matter that both sizeof are equal.
You cannot have it both ways.
Either, the calling convention indicates the returned value if of a given fixed type (and sizeof doesn't matter),
or the sizeof matters, and the type of the returned object is variable.
Anyway, you cannot "undo" an upcast in general.
So this approach does not work in general, period.
 
I don't really have time for this, it is almost 1am and I need to get up tomorrow. What I am saying, and let me emphasize it is that you cannot have a covariant by-value return type. The size matters (how many times do I need to say that?) When you return a pointer, caller and callee know the size of the returned object: the size of a pointer. When you return by value the only agreement that can be achieved is by using the same type.
Do you understand that the size of a pointer to base and a pointer to derived are the same?
Do you understand that if you return by value, the size of the returned value would be dependent on the value returned by the final overrider and unknown to the caller?
 
4:50 AM
@DavidRodríguez-dribeas "The size matters (how many times do I need to say that?)" You can repeat that forever if you wish.
 
Either, the calling convention indicates the returned value if of a given fixed type (and sizeof doesn't matter), or the sizeof matters, and the type of the returned object is variable. The calling convention determines who is responsible for reserving the space for the object, which (and for sound technical reasons) is the caller in all current calling conventions. The caller must know how much space it needs to reserve.
 
What you said implies that it does not matter.
@DavidRodríguez-dribeas It does not matter.
 
Tell me how anything I said means that it does not matter?
 
@DavidRodríguez-dribeas This is false.
@DavidRodríguez-dribeas I did previously.
 
@curiousguy Explain why that is false
 
4:52 AM
"Either, the calling convention" ...
@DavidRodríguez-dribeas For the exact same reason covariant ptr work.
You need to understand how they work in general.
 
I do understand how it works, or so I believe, but enlighten me
 
@DavidRodríguez-dribeas You said that the callee does a downcast, and the caller an upcast.
This cannot be made to work in general.
In general, the caller and callee must have exactly matching return type.
 
I said that could be an option. The only strong point I made is that size is an issue for covariant value return types. But go on
 
Even for pointers.
Because an upcast, in general, cannot be undone.
The information can be lost during an upcast.
 
Java generics are full of it
And in this particular case all the information is available to the compiler
 
4:55 AM
This is not Java, this is C++.
With a different inheritance model.
An upcast cannot be undone, because some information might be lost.
 
Ok, so they must agree on a type, what type is it?
 
It is like undone a cast to int from float.
 
It is not, but go on, I want to go to sleep
 
@DavidRodríguez-dribeas The declare type of the named function.
 
What function, the one in base or the one in derived?
 
4:57 AM
The one the caller names in his code.
If the object is of declared type base, it is the base function.
 
Ok, so depending on what the static type of the object on which the operation is called, is that it?
 
Same for derived.
There are as many conventions as there are classes (in general - in some case you can optimise away).
 
void f( base* b ) {
g( b->vfunc() );
}
 
@DavidRodríguez-dribeas Exactly.
@DavidRodríguez-dribeas The convention would be the one established for base::vfunc.
This means that there can be many different implementations for one virtual function.
 
Now say that I call f( new base ) and f( new derived ), how much space does f allocate for the return value of vfunc(), what is the type of it?
Your last two statements contradict, either the type is that of the static object, or it is always the one of the base
 
4:59 AM
(...) Which is not new: before covariance was allowed in C++, this was already the case.
@DavidRodríguez-dribeas as the declared type of base::vfuncsays.
 
@curiousguy Agreed to that, there are multiple overriders
@curiousguy Ok, we are getting somewhere. And what is the type of the expression? The one in base I guess?
 
@DavidRodríguez-dribeas I mean that in one class Derived, you can have many implementations for a given virtual function.
@DavidRodríguez-dribeas Yes.
The convention is selected according to declared type.
 
So you are saying now that derived::vfunc will generate multiple different functions that differ on the return type?
 
But nothing here is new.
@DavidRodríguez-dribeas In general, ye.
This is also the case when MI is used, and the overriden function is not from the primary base.
Two functions must be geneated:
 
Let's be precise: the calling convention is fixed for the architecture, it is the set of rules that dictate how function calls are performed.
 
5:03 AM
- one for the virtual func in non-primary base class
- one for the derived class
@DavidRodríguez-dribeas The calling convention is a set of rules, which describe how the member functions of a given class can be called.
 
@curiousguy That is bullshit. Compile a test program and run nm in linux of whatever the object analyzer is to see how many functions are generated.
 
@DavidRodríguez-dribeas OK you saying nonsense.
 
Take a read if you prefer to one of the ABI (the Itanium C++ ABI is publicly available) and you will see that virtual functions generate only one symbol
 
You are incompetent in some "advanced" areas of C++, and do not wish to learn.
You do not understand what I write,
You do not understand what what you write implies.
 
@curiousguy No, you are saying nonsense. And the fact that you believe something does not make it true. Seriously, analyze the generated code and you will see yourself that there is a single function generated for derived::vfunc
 
5:05 AM
You do not understand virtual calls, MI, virtual base classes, templates....
 
Seriously, I was in the C++ committee.
3
I know what I am talking about.
 
Good night. Seriously you have a problem with your attitude.
 
I give up, really.
YOU have a problem because you cannot admit when you are wrong.
 
Were you? Can you tell me your real name so that I can run it by Alisdair Meredith, Dietmar Khül and John Lakos tomorrow in the office? They might remember you
 
5:07 AM
Goodbie.
@DavidRodríguez-dribeas No way.
Goodbie.
 
Se coge antes a un mentiroso que a un cojo.
Try running that through google translate if you can't read Spanish
I thought we were having a serious conversation. At any rate, if you get the type, read the Itanium C++ ABI, or "The C++ Object Model", or compile a test program and look at the generated symbols (hint: virtual destructors will generate multiple symbols, but that is the only virtual function that generates multiple symbols)
Bye
BTW, if multiple functions were generated, which pointer would be stored in the vtable for the type? Or maybe there is also N vtables for a type that is N-levels deep in the hierarchy?
 
 
14 hours later…
7:22 PM
@DavidRodríguez-dribeas Hey, we had a c++ committee in highschool too! And a word perfect board ;)
2
 

  last day (19 days later) »