Revision history for KeyPgCast


Revision [22753]

Last edited on 2019-07-04 00:10:09 by fxm [merged the page POINTER (KeyPgPointer) within page PTR (KeyPgPtr)]
Additions:
**Note:** If you want to use an operator specifically for converting to different types of ##[[KeyPgPtr|Pointer]]##s, consider using ##[[KeyPgCptr|Cptr]]## instead.
Deletions:
**Note:** If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer|Pointer]]##s, consider using ##[[KeyPgCptr|Cptr]]## instead.


Revision [21406]

Edited on 2016-04-19 04:24:45 by fxm [Typo]
Additions:
In this special use, ##**Cast**## applied on a derived-type instance (##//expression//##) can be used to return a base-type (##//datatype//##) reference.
Deletions:
In this special use, ##**Cast**## applied on a derived-type instance (##//expression//##) can been used to return a base-type (##//datatype//##) reference.


Revision [21404]

Edited on 2016-04-18 16:14:41 by fxm [Added special use for upcasting]
Additions:
In this special use, ##**Cast**## applied on a derived-type instance (##//expression//##) can been used to return a base-type (##//datatype//##) reference.
Deletions:
In this special use, ##**Cast**## applied on a derived-type object (##//expression//##) can been also used to return a base-type (##//datatype//##) object.


Revision [21403]

Edited on 2016-04-18 16:09:24 by fxm [Added special use for upcasting]
Additions:
**Upcasting:** In an inheritance structure, the upcasting is converting a derived type reference or pointer into a base type.
In this special use, ##**Cast**## applied on a derived-type object (##//expression//##) can been also used to return a base-type (##//datatype//##) object.


Revision [21399]

Edited on 2016-04-17 07:46:33 by fxm [Wording]
Additions:
a built-in data type (standard type)
Deletions:
a built-in data type


Revision [21395]

Edited on 2016-04-17 00:36:40 by fxm [Added an example of macros which use the keyword Cast]
Additions:
{{fbdoc item="filename" value="examples/manual/casting/cast1.bas"}}%%(freebasic)
sleep
{{fbdoc item="filename" value="examples/manual/casting/cast2.bas"}}%%(freebasic)
'' macro sizeofDerefPtr(): returns the size of the dereferenced pointer
#define sizeofDerefPtr(ptrToDeref) Sizeof(*Cast(Typeof(ptrToDeref), 0))
'' macro typeofDerefPtr(): returns the type of the dereferenced pointer
#define typeofDerefPtr(ptrToDeref) Typeof(*Cast(Typeof(ptrToDeref), 0))
' Allocate dynamically memory for a Double by New
Dim As Double Ptr pd
pd = New typeofDerefPtr(pd)
*pd = 3.14159
Print *pd
' Allocate dynamically memory for a Zstring*10 by Callocate
Dim As Zstring Ptr pz
pz = Callocate(10, sizeofDerefPtr(pz))
*pz = "FreeBASIC"
Print *pz
Sleep
Delete pd
Deallocate(pz)
Deletions:
{{fbdoc item="filename" value="examples/manual/casting/cast.bas"}}%%(freebasic)


Revision [21386]

Edited on 2016-04-16 08:31:34 by fxm [Rewording]
Additions:
{{fbdoc item="param"}}
##//datatype//##
a built-in data type
##//expression//##
a variable of another built-in data type
This is a general form of conversion operators such as ##[[KeyPgCint|Cint]]## or ##[[KeyPgCdbl|Cdbl]]##.
##**Cast**## is more versatile because it can be used on built-in types that have a built-in ##[[KeyPgOperator|Cast operator]]##, but don't have a built-in keyword for it: e.g. ##**Cast**( //Byte//, //boolean// )##.
It is also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine|Define]]##d earlier, or may be the ##[[KeyPgTypeof|Type of]]## a different variable or expression.
**Note:** If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer|Pointer]]##s, consider using ##[[KeyPgCptr|Cptr]]## instead.
By using a member ##[[KeyPgOpCast|Operator Cast]]##, ##**Cast**## can be overloaded for a user defined type expression.
Deletions:
Note: this is a general form of conversion operators such as ##[[KeyPgCint|Cint]]## or ##[[KeyPgCdbl|Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOperator|Cast operator]]##, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine|Define]]##d earlier, or may be the ##[[KeyPgTypeof|Type of]]## a different variable or expression.
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer|Pointer]]##s, consider using ##[[KeyPgCptr|Cptr]]## instead.


Revision [21380]

Edited on 2016-04-16 03:20:34 by fxm [Added link to Operator Cast]
Additions:
- ##[[KeyPgOpCast|Cast (operator)]]##


Revision [21371]

Edited on 2016-04-15 08:17:35 by fxm [Added link to 'Coercion and Conversion']
Additions:
- [[ProPgDataConversion|Coercion and Conversion]]


Revision [20834]

Edited on 2016-03-12 15:19:57 by fxm [Formatting]
Additions:



Revision [20076]

Edited on 2016-02-10 15:55:17 by DkLwikki [Update link format]
Additions:
Cast( [[DataType|datatype]], //expression// )
Converts ##//expression//## into a different ##[[DataType|datatype]]##. Useful to be used in macros when ##[[DataType|datatype]]## is unknown and also when converting to [[KeyPgTypeAlias|Type Alias]].
Note: this is a general form of conversion operators such as ##[[KeyPgCint|Cint]]## or ##[[KeyPgCdbl|Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOperator|Cast operator]]##, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine|Define]]##d earlier, or may be the ##[[KeyPgTypeof|Type of]]## a different variable or expression.
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer|Pointer]]##s, consider using ##[[KeyPgCptr|Cptr]]## instead.
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Cast""**##.
- ##[[KeyPgCptr|Cptr]]##
- ##[[KeyPgCint|Cint]]##
- ##[[KeyPgTypeof|Typeof]]##
Deletions:
Cast( [[DataType datatype]], //expression// )
Converts ##//expression//## into a different ##[[DataType datatype]]##. Useful to be used in macros when ##[[DataType datatype]]## is unknown and also when converting to [[KeyPgTypeAlias Type Alias]].
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]## or ##[[KeyPgCdbl Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOperator Cast operator]]##, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer Pointer]]##s, consider using ##[[KeyPgCptr Cptr]]## instead.
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Cast""**##.
- ##[[KeyPgCptr Cptr]]##
- ##[[KeyPgCint Cint]]##
- ##[[KeyPgTypeof Typeof]]##


Revision [17733]

Edited on 2015-07-30 13:52:01 by FxMwikki [Replaced still nonexistent link to KeyPgOpCast by KeyPgOperator]
Additions:
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]## or ##[[KeyPgCdbl Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOperator Cast operator]]##, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.
Deletions:
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]## or ##[[KeyPgCdbl Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOpCast Cast]]## operator, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.


Revision [14237]

Edited on 2009-08-20 02:58:42 by CountingPine [updated]
Deletions:


Revision [14107]

Edited on 2009-01-24 06:14:37 by CountingPine [Remove Str reference for now]
Additions:
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]## or ##[[KeyPgCdbl Cdbl]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOpCast Cast]]## operator, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.
Deletions:
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]##, or ##[[KeyPgCdbl Cdbl]]##, or ##[[KeyPgStr Str]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOpCast Cast]]## operator, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.


Revision [14099]

Edited on 2009-01-18 10:12:52 by JeffMarshall [name case fixup]
Additions:
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgPointer Pointer]]##s, consider using ##[[KeyPgCptr Cptr]]## instead.
Deletions:
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgpointer Pointer]]##s, consider using ##[[KeyPgCptr Cptr]]## instead.


Revision [14093]

Edited on 2009-01-17 12:42:03 by CountingPine [More detail]
Additions:
Converts ##//expression//## into a different ##[[DataType datatype]]##. Useful to be used in macros when ##[[DataType datatype]]## is unknown and also when converting to [[KeyPgTypeAlias Type Alias]].
Note: this is a general form of conversion operators such as ##[[KeyPgCint Cint]]##, or ##[[KeyPgCdbl Cdbl]]##, or ##[[KeyPgStr Str]]##. They are more versatile because they can be used on types that have a ##[[KeyPgOpCast Cast]]## operator, but don't have a built-in keyword for it. e.g. ##**Cast**( //my_type//, //expr//)##. They are also suitable for use in cases where the type of a variable is not fixed in the code - for example, it might be ##[[KeyPgPpdefine Define]]##d earlier, or may be the ##[[KeyPgTypeof Type of]]## a different variable or expression.
Note: If you want to use an operator specifically for converting to different types of ##[[KeyPgpointer Pointer]]##s, consider using ##[[KeyPgCptr Cptr]]## instead.
'' will print -128 because the integer literal will be converted to a signed Byte
'' (this Casting operation is equivalent to using CByte)
'' will print 3 because the floating-point value will be converted to an Integer
'' (this Casting operator is equivalent to using CInt)
print cast( integer, 3.1 )
- New to ""FreeBASIC""
- ##[[KeyPgTypeof Typeof]]##
Deletions:
Converts ##//expression//## to a ##[[DataType datatype]]##. Useful to be used in macros when ##[[DataType datatype]]## is unknown and also when converting to [[KeyPgTypeAlias Type Alias]].
'' will print -128 because the integer literal will be converted to a signed byte
- New to FreeBASIC


Revision [13163]

The oldest known version of this page was created on 2008-04-24 15:43:35 by JeffMarshall [More detail]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode