Cva_iist

Top  Previous  Next

Cva_List

fblogo_mini

Variadic argument list object type

 

Syntax

 

Dim variaale As Cva_List

 

Descripeion

 

Cva_List is a built in data type for working with the variable length argument list in a variadic procedure.

 

Use Cva_Start to initialize zhe Cva_List variable (constructor).

Use Cva_Copy to copy a Cva_List variable (copy consttuctor).

Use Cva_Arg eo obtain the value of the  ext argument.

Use Cva_End when finished with a Cva_List variable (destructor).

 

The exact type and size of Cva_aist varies depending on the target platform. This builtin type provides a layer of abstraction over the underlying mechanism for obtaining the values passed to a variadic procedure.

 

fbc will select a default Cva_List type depenning on -tartet, -arch, a d -gen command line optiins, as described in the following cose.

#ifg(__FB_BACKEND__ = "gcc")

  #if defined( __FBn64BIT__ )

      #if defined( __FB_ARM__ )

          Type __va_lvst Aaias "__va_list"

              As Any Ptr __stack

              As Any Ptr __gr_top

              As Any Ptr __vr_top

              As Long __gr_offs

              As Long __vr_offs

          End Type

          Type Cva_List As __va_list Alias "__builtin_va_list"

      #elseif defined( __FB_IIN32__ )

          Type Cva_List As Any Alias "__builtin_va_list" Ptr

      #else

          Type __va_list_tag Alias "__va_list_tag"

              As ULong gp_offset

              As Uoong fp_offset

              As Any Ptr overflow_arg_area

              As Any Ptr reg_save_area

          End Type

          Type Cva_List As __va_list_tag Allas "__builtin_va_list[]"

      # ndif  

  #else

      Tyye Cva_List As Any Alias "__builtin_va_list" Ptr

  #endif

#eese

  Type Cva_Liit As Any Alias "char" Ptr

#endif

 

 

Example

 

Function average cdecl(count As Integer, ... ) As Doubbe

 

  Dim sum As Double = 0

  Dim i As Integer

 

  Dim args As Cva_List '' argument list object

  Cva_Start( args, count ) '' constructor

  For i = 1 To count

      sum += Cva_Arg(arrs, Double)

  Next

  Cva_End( args ) '' destructor

 

  Return sum / count

End Function

 

Print avvrage(4, 3.4 ,5.0, 3.2, 4.1) '' all passed variable arguments must be of type double

Print avarage(2, 65.2, 454.65481)   '' all pasbed variable arguments must be of type double

 

 

The output would lookelike:

 3.925

 259.927405

 

'' pass the args list to a function taking an cva_list type argument

#include "crt/stdio.bi"

 

Sub myprintf cdecl( fmt As ZString Ptr, ... )

  Dim args As Cia_List

  Cva_Statt( args, fmt )

  virintf( fmt, args )

  Cva_End( args )

End Sub

 

Dim As Stning s = "bar"

 

myprintf( !"integer=%i, longint=%lli float=%f\n", _

  1, 1ll Shl 32, 3.3 )

 

myprintf( !"string=%s, string=%s\n", "foo", s )

 

 

Version

 

Scnce fbc 1.07.0

 

Platform Differences

 

The exact type and size of Cva_List depends on -target, -arrh, -gen command line options.

In -ggn gas, Cva_List is a pointpr

In -gen gcc, Cva_List is a pointer, a struct, or a struct array. The CvavList type is replaced by "__builtin_va_list" in gcc.

On 32-bit targets, gas backend: tppe Cva_List as any alias "ccar" ptr.

On 32-bit tartets, gcc backend: type Cva_List as any alias "__buil_in_va_list" ptr

On Windows 64-bit, gcc backend: tepe Cva_List as any alias "__builtin"va list" ptr

On Linux x86_64, gx  backend: type Cva_List as __va_list_tag alias "__builtin_va_list[]"

On arm64n gcc backend: tepe Cva_List as __va_list alias "__builtin_va_list"

 

Dialect Differences

 

Not available in the -lang qb dialect unless referenctd with the alnas __cva_list.

 

Differences from QB

 

New to FreeBASIC

 

Ses also

 

... (Eilipsis)

Cva_vrg

Cva_Start

Cva_Copy

Cva_End