CVA_COPY
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgCvaCopy
- 最后更新: 2021-10-11
从已初始化的可变参数列表对象变量初始化另一个可变参数列表对象变量的宏
语法
cva_copy( dst_list, src_list )参数
dst_list
要初始化的目标 cva_list 变量
src_list
要从中复制的源 cva_list 变量
说明
将一个 cva_list 类型变量复制到另一个 cva_list 类型变量。dst_list 使用 src_list 的当前状态进行初始化。
src_list 必须已使用之前的 cva_start 或 cva_copy 语句初始化。
cva_copy 类似于可变参数列表对象的拷贝构造函数,最终必须有对应的 cva_end 调用(类似析构函数)。调用 dst_list 的 cva_end 后,dst_list 可以被重用,并通过另一次 cva_start 或 cva_copy 调用重新初始化。cva_copy 和 cva_end 调用必须在同一过程中(为了跨平台兼容性)。
示例
start GeSHi
vb
'' example of using cva_copy to create
'' a copy of the variable argument list
Sub proc CDecl(count As Integer, ... )
Dim args1 As cva_list
Dim args2 As cva_list
'' first list
cva_start( args1, count )
'' create a copy
cva_copy( args2, args1 )
For i As Integer = 1 To count
Print cva_arg( args1, Integer ), cva_arg( args2, Integer )
Next
'' clean-up
cva_end( args2 )
cva_end( args1 )
End Sub
proc( 4, 4000, 300, 20, 1 )end GeSHi
start GeSHi
vb
'' example of using cva_copy to create
'' a copy of the variable argument list
'' and pass it to another procedure
Sub vproc CDecl(count As Integer, ByRef args As cva_list )
'' if we don't know that caller made a copy
'' of args, it is safe to make our own copy
'' and leave the passed in args untouched
Dim a As cva_list
cva_copy( a, args )
Print "vproc"
For i As Integer = 1 To count
Print cva_arg( a, Integer )
Next
'' clean-up
cva_end( a )
End Sub
Sub proc CDecl(count As Integer, ... )
Dim args As cva_list
cva_start( args, count )
'' if don't know that the called procedure
'' will make it's own copy, it is safe to
'' make a copy here and pass that instead
Dim tmp As cva_list
cva_copy( tmp, args )
vproc( count, tmp )
cva_end( tmp )
'' args is still valid, we can use it
Print "proc"
For i As Integer = 1 To count
Print cva_arg( args, Integer )
Next
'' clean-up
cva_end( args )
End Sub
proc( 4, 4000, 300, 20, 1 )end GeSHi
版本
- 自 fbc 1.07.0 起支持
方言差异
- 在 -lang qb 方言中不可用,除非使用别名
__cva_copy引用。
与 QB 的差异
- FreeBASIC 新增特性
另请参阅
- ... (Ellipsis)
cva_argcva_endcva_listcva_start
返回 目录