Help Center
Help CenterFreeBASIC

__FB_ARG_COUNT__keyword

Intrinsic define (macro) performed by the compiler.

Intrinsic Defineskeyworddocumented

Syntax

__FB_ARG_COUNT__( args... )

Parameters

NameDescription
args...argument list

Description


Counts the number of arguments in the argument list (args...) and returns the corresponding value.
A value is always returned, with 0 corresponding to an empty argument list.

Because the argument separator is the comma (,), the returned value for a non-empty argument list is the number of main commas (non-nested) plus 1.

Remarks

Version


  • Since fbc 1.08.0

Differences from QB


  • New to FreeBASIC

See also


Example


#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

'/

' 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

'/

Reference

  • Documented in KeyPgDdfbargcount.html