f_size ====== Return the number of elements of a scalar or an array as ``integer(f_size_t)``, without accessing any element. .. code-block:: fortran use futile ! or: use f_utils, only: f_size ! or: use f_size_module, only: f_size ``f_size_module`` (``flib/f_size.f90``) defines the interface; ``f_utils`` and ``futile`` re-export it unchanged. Signature --------- Generated from the FYPP documentation stub ``doc/generated/f_size_doc.f90`` (emitted by ``fypp/size-doc.fypp`` from the same loops as ``flib/f_size.f90``, which ``fypp/generate-sizeof.py`` generates from ``fypp/size.fypp``). In the signature, ``any_intrinsic`` is a documentation placeholder: the argument may be of any intrinsic type, of any Futile :ref:`ABI kind `. The signature line merges both calling forms; their exact argument order is given in the description below and under `Typical calls`_. .. f:autointerface:: f_size Typical calls ------------- .. code-block:: fortran n = f_size(array) ! any ABI type/kind, rank 0-7 n = f_size(value) ! 1 for any scalar n = f_size('abc') ! 1: a scalar string is one element n = f_size(len(names), names) ! character array, element length first n = f_size(names) ! the one-argument array form also works Returns ------- The element count as ``integer(f_size_t)``, a kind compatible with C ``size_t``; Fortran still treats the integer as signed. A scalar, including a zero-length string, counts as one element. An array with any zero extent has zero elements. Noncontiguous sections count their payload elements, excluding stride gaps, descriptors and allocation overhead. Supported kinds and ranks ------------------------- Scalar and array overloads cover the concrete ``f_precisions`` :ref:`ABI kinds ` and ranks zero through seven; semantic kind aliases do not add duplicate overloads. The ``character(len=ln)`` row is the character-array form ``f_size(ln, x)``. .. fortran-specifics:: f_size :args: x, ln Notes ----- .. rubric:: No element access, pure Array extents are obtained directly in ``f_size_t`` through ``shape(x, kind=f_size_t)``. No array element is read, and the inquiry can be called from pure procedures. .. rubric:: Representable counts Let ``H = huge(0_f_size_t)``. An element count must be at most ``H``; representability of every positive intermediate product is a precondition. Nonpositive extents yield zero before any multiplication, and two negative extents do not turn an empty shape into a positive count. ``f_size`` performs no overflow termination or error reporting, and no result, saturation or wrapping behaviour is promised outside that range. The byte-size limits are tabulated on the :doc:`f_sizeof` page. .. rubric:: Migration The result kind changed from default integer to ``f_size_t``: dependent Fortran code must be recompiled against the updated module files. Neither compilation nor the ordinary regression tests require FYPP. Examples -------- The example is compiled and run by CI (``tests/flib/size_contracts.F90``). .. fortranliteral:: tests/flib/size_contracts.F90 :marker: size_contracts :dedent: 2 See also -------- * :doc:`f_sizeof` -- payload storage in bytes, with the same kinds and ranks. * :doc:`f_memcpy` -- ``n`` counts source elements, as returned by ``f_size``. * :doc:`f_subptr` -- borrowed rank-one views whose ``n`` counts elements.