Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

dmd.chkformat

Check the arguments toprintf andscanf against theformat string.
Authors:
Walter Bright
License:
Boost License 1.0

Sourcechkformat.d

Documentationhttps://dlang.org/phobos/dmd_chkformat.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/chkformat.d

boolcheckPrintfFormat(Locloc, scope const char[]format, scope Expression[]args, boolisVa_list, ErrorSinkeSink);
Check that arguments to a printf format string are compatible with that string. Issue errors for incompatibilities.
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 tos 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:
Locloclocation for error messages
char[]formatformat string
Expression[]argsarguments to match with format string
boolisVa_listif a "v" function (format check only)
ErrorSinkeSinkwhere the error messages go
Returns:
true if errors occurred

ReferencesC99 7.19.6.1https://www.cplusplus.com/reference/cstdio/printf/

boolcheckScanfFormat(Locloc, scope const char[]format, scope Expression[]args, boolisVa_list, ErrorSinkeSink);
Check that arguments to a scanf format string are compatible with that string. Issue errors for incompatibilities.
Follows the C99 specification for scanf.
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-standard formats
  7. 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:
Locloclocation for error messages
char[]formatformat string
Expression[]argsarguments to match with format string
boolisVa_listif a "v" function (format check only)
ErrorSinkeSinkwhere the error messages go
Returns:
true if errors occurred

ReferencesC99 7.19.6.2https://www.cplusplus.com/reference/cstdio/scanf/

Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:05:46 2026

[8]ページ先頭

©2009-2026 Movatter.jp