Repository navigation
Fb Arg Count
Home › Intrinsic Defines › FB_ARG_COUNT
Intrinsic define (macro) performed by the compiler.
__FB_ARG_COUNT__( args... )args...
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.
- New to FreeBASIC
#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
'/Category: Intrinsic Defines
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing