Are you an LLM? You can read better optimized documentation at /zh\official\language\defines\KeyPgDdfbargcount.md for this page in Markdown format
FB_ARG_COUNT
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgDdfbargcount
- 最后更新: 2024-06-02
编译器执行的内置定义(宏)。
语法
**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__
返回 目录