Skip to content

Instantly share code, notes, and snippets.

@dlOuOlb
Last active January 22, 2026 06:58
Show Gist options
  • Select an option

  • Save dlOuOlb/bc2b265351633935753d6f57617e2e79 to your computer and use it in GitHub Desktop.

Select an option

Save dlOuOlb/bc2b265351633935753d6f57617e2e79 to your computer and use it in GitHub Desktop.
An example of C23 function properties: effectless, idempotent, independent, and stateless.
#if !__STDC__ || __STDC_VERSION__ < +202311L
# error "This code is written in standard C23."
#else
static bool ψ = true;
static bool non_independent( void ) { return ψ; }
static void non_effectless( register const bool ζ ) { ψ = ζ; return; }
static bool non_stateless( register const bool ζ ) { static bool φ = true; return φ = φ && ζ; }
static void non_idempotent( register bool ξ[ const restrict static sizeof "" ] ) { *ξ = !*ξ; return; }
static bool reproducible( void ) { return non_stateless( non_independent( ) ); } // effectless ∩ idempotent
static bool unsequenced( void ) { return false; } // effectless ∩ idempotent ∩ independent ∩ stateless
extern signed int main( void )
{
/* ψ φ δ */ auto bool δ = unsequenced( );
/* 1 1 0 */
/* . : 1 */ δ = reproducible( );
/* . : : */ δ = reproducible( );
/* 0 */ non_idempotent( &δ );
/* 1 */ non_idempotent( &δ );
/* 0 . */ non_effectless( !δ );
/* 0 1 1 */
/* . 0 0 */ δ = reproducible( );
/* . : : */ δ = reproducible( );
/* 1 */ non_idempotent( &δ );
/* 0 */ non_idempotent( &δ );
/* 1 . */ non_effectless( !δ );
/* 1 0 0 */
/* ψ φ δ */ return unsequenced( );
}
#endif

§ 6.7.13.8.1 — N3220

unsequenced

reproducible

stateless

  • A function definition f is stateless if any definition of an object of static or thread storage duration in f or in a function that is called by f is const but not volatile qualified.

effectless

  • A function definition is effectless if the derived function pointer value is effectless.
  • A function pointer value f is effectless if any evaluation of a function call that calls f is effectless.
  • An evaluation of a function call is effectless if any store operation that is sequenced during the call is the modification of an object that synchronizes with the call; if additionally the operation is observable, there shall be a unique pointer parameter P of the function such that any access to X shall be to an lvalue that is based on P.

idempotent

  • A function definition is idempotent if the derived function pointer value is idempotent.
  • A function pointer value f is idempotent if any evaluation of a function call that calls f is idempotent.
  • An evaluation E is idempotent if a second evaluation of E can be sequenced immediately after the original one without changing the resulting value, if any, or the observable state of the execution.

independent

  • A function definition is independent if the derived function pointer value is independent.
  • A function pointer value f is independent if for any object X that is observed by some call to f through an lvalue that is not based on a parameter of the call, then all accesses to X in all calls to f during the same program execution observe the same value; otherwise if the access is based on a pointer parameter, there shall be a unique such pointer parameter P such that any access to X shall be to an lvalue that is based on P.

observable

  • A store operation to an object X that is sequenced during a function call such that both synchronize is said to be observable if X is not local to the call, if the lifetime of X ends after the call, if the stored value is different from the value observed by the call, if any, and if it is the last value written before the termination of the call.

observed

  • An object X is observed by a function call if both synchronize, if X is not local to the call, if X has a lifetime that starts before the function call and if an access of X is sequenced during the call; the last value of X, if any, that is stored before the call is said to be the value of X that is observed by the call.

local

  • An object is local to a call to a function f if its lifetime starts and ends during the call or if it is defined by f but does not escape.

synchronize

  • A function call and an object X synchronize if all accesses to X that are not sequenced during the call happen before or after the call.

escape

  • An object definition of an object X in a function f escapes if an access to X happens while no call to f is active.

sequenced

  • An operation is said to be sequenced during a function call if it is sequenced after the start of the function call and before the call terminates.

store operation

  • Operations that allow to change the execution state are considered as store operations, for the purposes of these attributes.

lvalue conversion

  • Operations that access the execution state, even indirectly, are considered as lvalue conversions for the purposes of these attributes.

object

  • Execution state that is described in the library clause, such as the floating-point environment, conversion state, locale, input/output streams, external files or errno are considered as objects for the purposes of these attributes.
@dlOuOlb
Copy link
Author

dlOuOlb commented Dec 29, 2025

@dlOuOlb
Copy link
Author

dlOuOlb commented Dec 31, 2025

Quizzes





Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment