Skip to content

FB_ARG_COUNT


编译器执行的内置定义(宏)。

语法

**FB_ARG_COUNT**( args... )

参数

args...

参数列表

说明

计算参数列表(args...)中的参数数量并返回对应的值。

始终返回一个值,0 对应空参数列表。

由于参数分隔符是逗号(,),非空参数列表的返回值是主逗号(非嵌套)的数量加 1。

示例

start GeSHi

vb
#macro m( args... )
    Print __FB_ARG_COUNT__( args )
#endmacro

m()
m(a)
m(b,c)
m(,d)
m(,e,)
m(,,,)

Sleep

/' Output:
 0
 1
 2
 2
 3
 4
'/

end GeSHi

start GeSHi

vb
' macro with a variadic parameter which can contain several sub-parameters:
'   To distinguish between the different arguments passed by a variadic_parameter,
'   you can first convert the variadic_parameter to a string using the Operator # (Preprocessor Stringize),
'   then differentiate in this string (#variadic_parameter) each passed argument by locating the separators (usually a comma)
'   in a [For...Next] loop based on the number of arguments (__FB_ARG_COUNT__) passed to the macro.

#macro average(result, arg...)
    Scope
        Dim As String s = #arg
        If s <> "" Then
            result = 0
            For I As Integer = 1 To __FB_ARG_COUNT__( arg ) - 1
                Dim As Integer k = InStr(1, s, ",")
                result += Val(Left(s, k - 1))
                s = Mid(s, k + 1)
            Next I
            result += Val(s)
            result /= __FB_ARG_COUNT__( arg )
        End If
    End Scope
#endmacro

Dim As Double result
average(result, 1, 2, 3, 4, 5, 6)
Print result

Sleep

/' Output :
 3.5
'/

end GeSHi

版本

  • 自 fbc 1.08.0 起支持

与 QB 的差异

  • FreeBASIC 新增特性

另请参阅

  • __FB_ARG_LEFTOF__
  • __FB_ARG_RIGHTOF__
  • __FB_ARG_EXTRACT__
  • __FB_ARG_LISTEXPAND__

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系