Why in documentation (KeyPgOpNew, KeyPgOperator for example) the paragraph "Syntax" describes a 'New/New[]' operator (overloaded or not overloaded) which returns an 'Any Ptr' while it returns its 'datatype Ptr'?
Similarly (KeyPgOpDelete, KeyPgOperator for example), we must provide a typed pointer to the 'Delete/Delete[]' operator and not an 'Any Ptr' (in addition, this is not written in documentation page).
Could I change the documentation accordingly?
New/Delete operator and returned/provided pointer type
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: New/Delete operator and returned/provided pointer type
That sounds right to me. I think we usually use DataType ptr in these cases.
Re: New/Delete operator and returned/provided pointer type
Yes: as datatype ptr
KeyPgOperator ⇒ FxMwikki [The 'New' and 'Delete' operators work with typed pointers]
KeyPgOpNew ⇒ FxMwikki [The 'New' operator returns a typed pointer]
KeyPgOpDelete ⇒ FxMwikki [The 'Delete' operator expects a typed pointer]
KeyPgOperator ⇒ FxMwikki [The 'New' and 'Delete' operators work with typed pointers]
KeyPgOpNew ⇒ FxMwikki [The 'New' operator returns a typed pointer]
KeyPgOpDelete ⇒ FxMwikki [The 'Delete' operator expects a typed pointer]
Re: New/Delete operator and returned/provided pointer type
I will go back for 'new' and 'delete' keywords:
- KeyPgOperator ⇒ FxMwikki [Go back before the previous changes]
- KeyPgOpDelete ⇒ FxMwikki [The 'Delete' operator expects a typed pointer]
- KeyPgOpNew ⇒ FxMwikki [Go back before the previous changes]
Remark:
Even if the overloaded New operator is declared to return 'As Any Ptr', at compilation time, we can verify that the real type of the returned pointer is 'UDT Ptr':Is that the compiler adds a final cast?
- Upon reflection, it is best to leave 'as any ptr' for the 'new' and 'delete' operators instead of 'as udt ptr', because one can not prejudge the allocation/deallocation type which will be used for the 'new'/'delete' overloaded operator.
- Don't impose a casting instruction in the 'new' operator body, depending on allocation type chosen.
(for example no problem with 'Operator = Callocate(size)', but problem with 'Operator = New Byte[size]': 'warning 4(1): Suspicious pointer assignment') - In case especially where the user forgets a necessary pointer casting in the 'delete' operator body, it is better to have an eventual error message at compile time 'warning 22(0): Deleting ANY pointers is undefined' than to have a crash without error message.
(for example no problem with 'Deallocate(buffer)', but problem with 'Delete[] buffer' => 'Execution bug')
- Don't impose a casting instruction in the 'new' operator body, depending on allocation type chosen.
- I'll just specify that the user must provide a typed pointer to the 'delete' operator.
- KeyPgOperator ⇒ FxMwikki [Go back before the previous changes]
- KeyPgOpDelete ⇒ FxMwikki [The 'Delete' operator expects a typed pointer]
- KeyPgOpNew ⇒ FxMwikki [Go back before the previous changes]
Remark:
Even if the overloaded New operator is declared to return 'As Any Ptr', at compilation time, we can verify that the real type of the returned pointer is 'UDT Ptr':
Code: Select all
Type UDT
Declare Operator New (ByVal size As UInteger) As Any Ptr
Declare Operator Delete (ByVal buffer As Any Ptr)
Dim As String s
End Type
#print typeof(New UDT)
Code: Select all
UDT PTR