CPROTO(1)

πŸ’– CPROTO β€” bestie edition πŸ’–

okay so real talk, this is cproto from the User commands crew, and it's genuinely one of those tools that looks boring and is secretly doing the most. it generates C function prototypes and converts function definitions. that's the whole personality. periodt.


✨ SYNOPSIS ✨

cproto [ option ...  ] [ file ...  ]

🌸 DESCRIPTION 🌸

πŸ“ Extracting

so cproto looks at the C source files you hand it and generates function prototypes for all the functions defined in there, dumping them to standard output. the function definitions can be old style or ANSI C style, it does not care, it's flexible like that. optionally you can also get it to output declarations for variables defined in the files. and if you give it no file argument at all? it just reads from standard input. lowkey chill.

πŸ¦‹ Converting ANSI C

cproto can convert function definitions in simple source files from the old style to the ANSI C style (peep BUGS for the limitations, bestie, don't say i didn't warn you). the original source files β€” plus any files pulled in by

#include "file"

directives sitting in the source code β€” will get overwritten with the converted code. yes, overwritten. no, there is no undo. πŸ™ˆ

if you don't give it any file names on the command line, it reads the source from standard input and writes the converted source to standard output. safe.

if there are any comments in the parameter declarations for a function definition, like in this example here:

main (argc, argv)
int argc;       /* number of arguments */
char *argv[];   /* arguments */
{
}

then the converted function definition comes out looking like:

int
main (
    int argc,       /* number of arguments */
    char *argv[]   /* arguments */
)
{
}

but if there are no comments? then the converted function definition is just:

int
main (int argc, char *argv[])
{
}

clean. simple. iconic.

πŸ’… Converting K&R C

cproto can also go the other way: convert function definitions from the ANSI style to the old K&R style. in this mode it also converts function declarators and prototypes that appear outside function bodies. heads up though β€” this is not a complete ANSI C to old C conversion. the program does not change anything within function bodies. hands off the body, that's the rule.

⭐ Lint-libraries

optionally, cproto can generate source in lint-library format. this is useful in environments where the lint utility is used to supplement prototype checking of your program. iykyk.


πŸ‘‘ OPTIONS πŸ‘‘

  • -a β€” convert function definitions from the old style to the ANSI C style.
  • -B directive β€” set the conditional compilation directive to output at the beginning of function definitions generated by the -b option. the default is
#ifdef ANSI_FUNC
  • -b β€” rewrite function definition heads to include both old style and new style declarations, separated by a conditional compilation directive. for example, the program can generate this function definition:
#ifdef ANSI_FUNC

int
main (int argc, char *argv[])
#else

int
main (argc, argv)
int argc;
char *argv[]
#endif
{
}
  • -C template β€” set the output format for function definitions with parameter comments. the -F and -P options let you set the format for prototypes and function definitions.

the format is specified by a template in the form

" int f ( a, b )"

but you may replace each space in this string with any number of whitespace characters. for example, the option

-F"int f(\n\ta,\n\tb\n\t)"

will produce

int main(
        int argc,
        char *argv[]
        )
  • -c β€” the parameter comments in the prototypes generated by the -f1 and -f2 options are omitted by default. use this option to enable the output of these comments. (they were just being shy fr.)
  • -D name[=value] β€” this option is passed through to the preprocessor and is used to define symbols for use with conditionals such as #ifdef.
  • -d β€” omit the definition of the prototype macro used by the -m option.
  • -E cpp β€” pipe the input files through the specified C preprocessor command when generating prototypes. by default, the program uses β€œgcc -E” via a pipe.
  • -E 0 β€” do not run the C preprocessor.
  • -e β€” output the keyword extern in front of every generated prototype or declaration that has global scope.
  • -F template β€” set the output format for function definitions as in the β€œ-C” option.
  • -f n β€” set the style of generated function prototypes where n is a number from 0 to 3. for example, consider the function definition
main (argc, argv)
int argc;
char *argv[];
{
}

if the value is 0, then no prototypes are generated. when set to 1, the output is:

int main(/*int argc, char *argv[]*/);

for a value of 2, the output has the form:

int main(int /*argc*/, char */*argv*/[]);

the default value is 3. it produces the full function prototype:

int main(int argc, char *argv[]);
  • -I directory β€” this option is passed through to the preprocessor and is used to specify a directory to search for files that are referenced with #include.
  • -i β€” by default, cproto only generates declarations for functions and variables having global scope. this option will output inline declarations as well.
  • -l β€” generate text for a lint-library (overrides the β€œ-f” option). the output includes the comment
/* LINTLIBRARY */

special comments LINT_EXTERN and LINT_PREPRO (a la β€œVARARGS”) respectively turn on the β€œ-x” option and copy comment-text to the output (for preprocessing in lint). use the comment

/* LINT_EXTERN2 */

to include externs defined in the first level of include-files. use the comment

/* LINT_SHADOWED */

to cause cproto to put β€œ#undef” directives before each lint library declaration (i.e., to avoid conflicts with macros that happen to have to have the same name as the functions, thus causing syntax errors).

note that these special comments are not supported under VAX/VMS, since there is no equivalent for the β€œ-C” option of the C preprocessor with VAX-C. πŸ’€
  • -M name β€” set the name of the macro used to surround prototype parameter lists when option -m is selected. the default is β€œP_”.
  • -m β€” put a macro around the parameter list of every generated prototype. for example:
int main P_((int argc, char *argv[]));
  • -N name β€” rather than filling in β€œvoid” for functions without parameters, use the given name.
  • -n β€” rather than filling in β€œvoid” for functions without parameters, use a comment β€œ/*empty*/”.
  • -O file β€” specify the name of the error file (default: standard error).
  • -o file β€” specify the name of the output file (default: standard output).
  • -P template β€” set the output format for generated prototypes as in the β€œ-C” option.
  • -p β€” disable promotion of formal parameters in old style function definitions. by default, parameters of type char or short in old style function definitions are promoted to type int in the function prototype or converted ANSI C function definition. parameters of type float get promoted to double as well. glow-up denied, sorry.
  • -q β€” do not output any error messages when the program cannot read the file specified in an #include directive.
  • -S β€” output only static declarations.
  • -s β€” by default, cproto only generates declarations for functions and variables having global scope. this option will output static declarations as well.
  • -T β€” copy type definitions from each file. (definitions in included-files are copied, unlike the β€œ-l” option).
  • -t β€” convert function definitions from the ANSI C style to the traditional style.
  • -U name β€” this option is passed through to the preprocessor and is used to remove any definitions of this symbol.
  • -V β€” print version information.
  • -v β€” also output declarations for variables defined in the source.
  • -X level β€” this option limits the include-file level from which declarations are extracted by examining the preprocessor output.
  • -x β€” this option causes procedures and variables which are declared β€œextern” to be included in the output.

🌈 ENVIRONMENT 🌈

the environment variable CPROTO is scanned for a list of options in the same format as the command line options. options given on the command line override any corresponding environment option. command line stays winning, as it should. πŸ’…


πŸ’€ BUGS πŸ’€

if an un-tagged struct, union or enum declaration appears in a generated function prototype or converted function definition, the content of the declaration between the braces is empty. yeah. just vibes in there. nothing else.

the program does not pipe the source files through the C preprocessor when it is converting function definitions (i.e., options -a, -b, -t). that is because cproto does the conversion by replacing strings, rather than by converting to/from lexical tokens. instead of using the C preprocessor, cproto tries to handle preprocessor directives and macros itself, to find type definitions. there are several limitations as a result:

  • the search-path for included files contains only β€œ/usr/include” and the directories listed by β€œ-I” options.
  • conditional directives (e.g., β€œ#if”) are ignored.
  • only macros without parameters are handled.
  • some comments in the function definition head are discarded.

the -v option does not generate declarations for variables defined with the extern specifier. this does not strictly conform to the C language standard but this rule was implemented because include files commonly declare variables this way.

when the program encounters an error, it usually outputs the not very descriptive message β€œsyntax error”. (your configuration may allow the extended error reporting in yyerror.c). not me getting a one-word error message and having to figure out my whole life 😭

options that take string arguments only interpret the following character escape sequences:

\n   newline
\s   space
\t   tab

VARARGS comments are not passed through on systems whose C preprocessors do not support this (e.g., VAX/VMS, MS-DOS).


🫢 AUTHORS 🫢

  • Chin Huang β€” cthuang@vex.net, cthuang@interlog.com
  • Thomas E. Dickey β€” dickey@invisible-island.net β€” modifications to support lint library, type-copying, and port to VAX/VMS.

πŸŽ€ SEE ALSO πŸŽ€

cc(1), cpp(1)


and that's a wrap, bestie πŸ¦‹ this was Version 4.8a, dated 2026-07-26 β€” go forth and prototype responsibly βœ¨πŸ’–

πŸ“¦ where this page comes from