QUICK REFERENCE

Conversion checklist

Use this sequence to prepare Python, convert it, and verify the generated C in your own build environment.

Prepare the Python

  1. Start with functions whose expected results you know.
  2. Choose a mode using Supported conversions, and follow its examples.
  3. For typed conversion, annotate parameters/results and keep variable types consistent. Supply all imported source modules.
  4. For runtime conversion, use explicitly supplied modules and the admitted string, container, class, function, and comprehension forms. Use annotations where a checked type boundary is useful.
  5. Assign every local and field before reading it. Include cases where branches or loops do not execute.

Convert and inspect

  1. Select Typed or Runtime in the Transpile menu, then click the Transpile button.
  2. Read diagnostics and correct rejected source forms. Review warnings on successful output.
  3. Convert again after edits. Save C only when it matches the intended source and settings.
  4. Review the generated function declarations and the selected mode's C caller requirements.

Build with a C11 toolchain

Use the dedicated PCFC11 Compile dialog, or Transpile → Other C Compilers… for GCC/MinGW-w64, Clang, MSVC or Clang-cl. The commands below show the equivalent external GCC workflow.

PyCForge emits source. Use a C application or test harness to call the generated functions. To compile a typed output to an object file with GCC:

gcc -std=c11 -Wall -Wextra -c output.c -o output.o

For runtime output with a Python main() callable without arguments, enable its optional entry wrapper:

gcc -std=c11 -DPYCF_RUNTIME_MAIN output.c -o program -lm

Follow typed string ownership and file status handling for typed output, or context lifetime and runtime errors for runtime output. Review compiler messages before running the program.

Complete typed C caller

Convert the add example to example.c. Save the following as caller.c in the same directory. Including the generated C makes its exact declarations available to this small standalone caller.

#include <inttypes.h>
#include <stdio.h>
#include "example.c"

int main(void)
{
    printf("%" PRId64 "\n", add(2, 3));
    return 0;
}

With a compatible GCC toolchain, build only the caller; do not also pass example.c, because it is already included:

gcc -std=c11 -Wall -Wextra caller.c -o caller

Run ./caller on Linux/macOS, or .\caller.exe in Windows PowerShell. It prints 5. For a larger C project, use matching declarations in a header and compile generated C as a separate translation unit.

Compare results with Python

For a source containing *import, compare against ordinary Python by changing the declaration to import in a reference copy. Use separate working directories with identical inputs. Check exit status, standard output, errors and resulting file bytes. Choose a bundled-import example.

Portable binary records

*import struct provides pack, unpack and calcsize over owned immutable bytes, with explicit byte order and checked format/range limits. Independent authors use the Portable binary records starter and the same BinaryFunction contracts. See Runtime bytes and binary records for formats, examples, ownership and errors.

Delimited records

Run this example in an empty directory. Inspect the printed field names and compare the resulting records.csv byte for byte. Text-mode display can hide CRLF differences. For accepted keywords, quoting and error handling, use the CSV reference.

*import csv

def main():
    rows = csv.DictReader(['name,value\n', '"north,west",12\n', 'south\n'], restval="0")
    print(rows.fieldnames)
    with open("records.csv", "w", encoding="utf-8", newline="") as output:
        writer = csv.DictWriter(output, ["value", "name"], lineterminator="\n")
        writer.writeheader()
        writer.writerows(rows)
    print(rows.line_num)
    return 0

Lazy iterator imports

The SDK's Lazy record pipelines starter exposes reusable chain, islice and pairwise operations under an independent namespace. The bundled itertools package uses these same contracts. Iterators retain their inputs and share their position through aliases. Exhaustion releases retained references; caller-owned files remain open until their own close or with-block exit.

*import itertools as it
def main():
    readings = it.chain([10, 12], [15, 21])
    for before, after in it.pairwise(it.islice(readings, 1, None)):
        print(after - before)
    return 0

This prints 3 and 6 on separate lines. chain accepts zero to eight positional inputs; islice accepts its two-, three- or four-argument form; pairwise accepts one input. Keywords, argument expansion, custom iteration hooks, generators and other itertools members are unsupported. Consult Import Help for input types, error recovery and work limits. Keep file-backed pipelines inside the file's with block.

Use independently authored formulas

The SDK's Author-defined measurement formulas starter supports new scalar logic through expression and ordered binding fields. Registered formulas can be called with their advertised positional/named/default arguments in Runtime programs and supplied modules. The initial profile accepts finite numbers and returns float64 or bool; it does not define new objects, iterators or binary buffers.

Each formula declares a bounded expression using arithmetic, comparisons, Boolean conditions and abs/sqrt/min/max primitives. An intermediate such as corrected = value - offset can be used in corrected * gain. Conditional expressions evaluate only their selected branch. Consult the package's Import Help for its exact formula and the engine-owned numerical, error and work limits.

SDK conversion verification does not run C or establish expected output. Compile and exercise the complete application in PyCForge, including errors and boundary values. A changed formula requires fresh conversion evidence and native qualification for its claimed behavior.

Retain a reproducible example

Keep the Python source, selected mode, settings, package version, generated C, test inputs, and expected results together. For a problem report, reduce the source to the smallest example that reproduces it and include the exact diagnostic or compiler message.