PFL Overview

Saturday, 3 October 2026 18:08 UTC

PFL is the base library for the PFL framework. It facilitates object-oriented programming in C and provides a base set of foundation classes.

The framework is modular and there are extension modules such as an event-driven server, an HTTP server, thread management, String formatting and templating.

PFL is designed for readability and syntactical consistency. In a similar way to Python, the PFL API is exposed in ordinary C function-call type syntax.

Classes

The base classes are similar to those found in Java, Python or C++. These include Strings, Integers, Floats, Decimals, Arrays, Linked-lists, Hash-Maps and others. Object instances are represented by typed pointers e.g. PFL_Str * my_str

PFL classes are extendable, polymorphic with single-inheritance and interfaces. They have both fixed functions and "virtual" overridable functions.

Casting and Autoboxing

PFL functions use caller macros "i functions" to automatically cast object parameters to the required class. Primitives such as char pointers or integers can be "autoboxed" to object instances when passed to these functions.

For example, a plain C string literal passed as a function parameter can be automatically converted to a PFL String object (PFL_Str).

Memory Management

PFL uses reference-counting to manage heap-allocated memory. Weak-references are supported to prevent circular references.

  • Scopes:

    Explicit "scopes" can be defined in the code. Container objects (like arrays) manage the scope of their contained items. An object within a scope will not be freed until at least the end of that scope.

  • Leak Detection:

    PFL includes a memory tracker, enabled by default in development mode. This will list any unfreed mallocs at program termination.

  • Stack & Global Objects:

    Literal objects such as strings and numerics (amongst others) can be created as constants in global storage or on the stack within a function. This avoids the need for heap memory allocation. Stack instances have automatic storage scope and can be used when they are not referenced outside of a single function call.

Example

Below is a short example program, demonstrating some of the features discussed here.

int 
main (int argc, char * argv[]) 
{
    // Initialise the PFL libraries
    pfl_env_init();

    // Create a new instance of an array with an initial capacity of 2
    PFL_Array * arr = pfl_array_new(2);

    // Define the explicit scope of the array instance.
    pfl_scope(arr)
    {
        // Add a 'Hello' string to the array. It will become a String object.
        pfl_array_i_append(arr, "Hello");

        // Add a 'World' string to the array.
        pfl_array_i_append(arr, "World");

        // Add an integer to the array too. It will become a Numeric object.
        // The array's capacity will expand automatically.
        pfl_array_i_append(arr, 123);

        // Print the array.
        // The result will be ["Hello", "World", 123]
        // (PFL objects print as valid JSON).
        pfl_println(arr);
    }
    pfl_scope_end; 
    
    
    // Terminate PFL
    pfl_exit(EXIT_SUCCESS, "OK");    
}