C ABI
Evaluate an element, substance, or material into an owned MAT record.
Basic examples
Evaluate water and print its JSON record. Link against snt-c:
#include <snt/c/mat.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
snt_mat_result* water = NULL;
snt_mat_error error = {0};
size_t required = 0;
if (snt_mat_substance_eval("H2O", 1, NULL, NULL, NULL, NULL, &water, &error))
return 1;
int failed = snt_mat_result_json(water, NULL, 0, &required, &error);
char* json = failed ? NULL : malloc(required);
failed = failed || !json ||
snt_mat_result_json(water, json, required, &required, &error);
if (!failed) puts(json);
free(json);
snt_mat_result_free(water);
return failed;
}
Supply physical inputs for a material mixture:
#include <snt/c/mat.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
snt_mat_result* brine = NULL;
snt_mat_error error = {0};
size_t required = 0;
if (snt_mat_material_eval("0.965 <H2O> 0.035 <NaCl>", "mass_fraction",
1, NULL, "1.02*g/cm3", "1*L", NULL, &brine, &error))
return 1;
int failed = snt_mat_result_json(brine, NULL, 0, &required, &error);
char* json = failed ? NULL : malloc(required);
failed = failed || !json ||
snt_mat_result_json(brine, json, required, &required, &error);
if (!failed) puts(json);
free(json);
snt_mat_result_free(brine);
return failed;
}
Common workflows
Task |
Call chain |
Result |
|---|---|---|
Evaluate a record |
|
Owned |
Size the JSON |
|
Required byte count |
Copy the JSON |
|
UTF-8 JSON in caller buffer |
Release the record |
|
No result; accepts |
Handle failure |
Check the integer return value and |
|
The normal chain is evaluate, query the JSON size, allocate the caller-owned
buffer, copy the JSON, then free the result handle. Use
snt_mat_element_eval, snt_mat_substance_eval, or
snt_mat_material_eval at the first step.
See the C binding guide and C API reference for the complete ownership rules.
Current limitations and differences
Compared with the canonical C++ implementation:
Results are opaque handles serialized as JSON. There are no native typed composition getters, mutable Element/Substance/Material objects, or incremental
add()operations.Matter inputs are PUQ expression strings. Optional outputs are JSON
null, and quantities contain a scalarvalue,units, andtext.Callers own the serialization buffer and must free every result. Return codes and
snt_mat_errorreplace C++ exceptions. The calculation rules and physical limits remain those of the native implementation.
Binding reference
This is a lookup index, not a sequence to read from top to bottom. Use
Common workflows above to choose a task, then find the exact C function
below. Integer-returning calls return zero on success. Output handles and
buffers are passed by pointer, and references such as &result are replaced
by the caller’s variables in real code.
snt_mat_element_eval(expression, natural, number_density, mass_density, volume, mass, &result, &error).snt_mat_substance_eval(...)with the same arguments.snt_mat_material_eval(expression, normalization, natural, number_density, mass_density, volume, mass, &result, &error).snt_mat_result_json(result, buffer, capacity, &required, &error); passNULLand zero capacity to query the required byte count.snt_mat_result_free(result)releases a record and acceptsNULL.
Matter arguments are optional PUQ expression strings. Passing NULL or an
empty string omits an input. normalization accepts number,
number_fraction, or mass_fraction; NULL means
number_fraction. The ABI returns canonical JSON rather than exposing typed
Element, Substance, or Material records directly.
Failures report code and message through snt_mat_error.