View source code
Display the source code in dmd/chkformat.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function dmd.chkformat.checkPrintfFormat

Check that arguments to a printf format string are compatible with that string. Issue errors for incompatibilities.

bool checkPrintfFormat (
  ref const(Loc) loc,
  scope const(char[]) format,
  scope Expression[] args,
  bool isVa_list,
  ErrorSink eSink
);

Follows the C99 specification for printf.

Takes a generous, rather than strict, view of compatiblity. For example, an unsigned value can be formatted with a signed specifier.

Diagnosed incompatibilities are:

1. incompatible sizes which will cause argument misalignment 2. deferencing arguments that are not pointers 3. insufficient number of arguments 4. struct arguments 5. array and slice arguments 6. non-pointer arguments to s specifier 7. non-standard formats 8. undefined behavior per C99

Per the C Standard, extra arguments are ignored.

No attempt is made to fix the arguments or the format string.

Parameters

NameDescription
loc location for error messages
format format string
args arguments to match with format string
isVa_list if a "v" function (format check only)
eSink where the error messages go

Returns

true if errors occurred

References

C99 7.19.6.1

https

//www.cplusplus.com/reference/cstdio/printf/

Authors

Walter Bright

License

Boost License 1.0