Arg_parser

Arg_parser is an argument parser that follows POSIX and GNU conventions for command-line arguments. There exist C++ and C versions of Arg_parser. The C++ version is implemented as a C++ class, while the C version is implemented as a single struct plus associated functions. Both are simpler, easier to use, and safer than 'getopt_long'.

For maximum stability, Arg_parser is self-contained. It extracts all the information it needs from its arguments to avoid referring to them later. This avoids index-out-of-bounds errors and allows the parser object to be passed as argument to other functions for further analysis.

Arg_parser does not modify its arguments (argc, argv), nor uses any global variables.

The C++ version of Arg_parser can also parse options from configuration files.

To use Arg_parser in your own programs simply copy the files 'arg_parser.h' and 'arg_parser.cc' (or 'carg_parser.h' and 'carg_parser.c' for the C version) in your source tree. See the examples in the manual and the file 'main.cc' ('cmain.c') in the source tarball for instructions.

Arg_parser was developed as the argument parser for GNU moe, because moe's argument parsing is rather complex. Then I used it in my other projects, including GNU ddrescue, GNU ed, lzip, GNU ocrad, tarlz, and zutils, with excellent results.

Documentation

The manual is available in the info system of the GNU Operating System. Use info to access the top level info page. Use info arg_parser to access the Arg_parser section directly.

An online manual for Arg_parser can be found at manual/arg_parser_manual.html.

Download

The latest released version of Arg_parser can be found at http://download.savannah.nongnu.org/releases/arg-parser/. You may also subscribe to arg-parser-bug and receive an email every time a new version is released.

To decompress Arg_parser tarballs you may need lzip from http://www.nongnu.org/lzip/lzip.html. Then use "tar -xf arg_parser[version].tar.lz" or "lzip -cd arg_parser[version].tar.lz | tar -xf -" to extract the files.

How to get help

For general discussion of errors (bugs) in Arg_parser, the mailing list arg-parser-bug@nongnu.org is the most appropriate forum. Please send messages as plain text. Do not send HTML, base64 MIME, nor multiple formats. Use a descriptive subject line with the word "arg_parser" in it.

An archive of the bug report mailing list is available at http://lists.nongnu.org/mailman/listinfo/arg-parser-bug.

How to help

To contact the author, either to report an error (bug) or to contribute fixes or improvements, send mail to arg-parser-bug@nongnu.org. Please send messages as plain text. If posting patches they should be in unified diff format against the latest version. They should include a text description.

You may use lzip. :-)

See also the Arg_parser project page at Savannah.

Maintainer

Arg_parser was written and is maintained by Antonio Diaz Diaz.

Licensing

Arg_parser is free software distributed under a 2-clause BSD license.

Valid HTML 4.01 Strict


Copyright © 2026 Antonio Diaz Diaz

You are free to copy, modify, and distribute all or part of this article without limitation.

Updated: 2026-03-20

This page does not use javascript.