Search

3.4. Auxiliary functions

download PDF
General syntax:
function <name>[:<type>] ( <arg1>[:<type>], ... ) { <stmts> }
SystemTap scripts may define subroutines to factor out common work. Functions may take any number of scalar arguments, and must return a single scalar value. Scalars in this context are integers or strings. For more information on scalars, see Section Section 3.3, “Variables” and Section Section 5.2, “Data types”. The following is an example function declaration.
function thisfn (arg1, arg2) {
return arg1 + arg2
}
Note the general absence of type declarations, which are inferred by the translator. If desired, a function definition may include explicit type declarations for its return value, its arguments, or both. This is helpful for embedded-C functions. In the following example, the type inference engine need only infer the type of arg2, a string.
function thatfn:string(arg1:long, arg2) {
return sprintf("%d%s", arg1, arg2)
}
Functions may call others or themselves recursively, up to a fixed nesting limit. See Section Section 1.6, “Safety and security”.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.