[swift-users] Why we need `__attribute__((sentinel(0,1)))`?
Greg Parker
gparker at apple.com
Tue Sep 6 23:30:30 CDT 2016
> On Sep 6, 2016, at 6:50 PM, 哀殿 via swift-users <swift-users at swift.org> wrote:
>
> Hello Swift community,
>
> I found `__attribute__((sentinel(0,1)))` at https://github.com/apple/swift-clang/blob/c52d85ede49adaec457400697b1d4c1b7ea12881/test/Analysis/variadic-method-types.m#L46.
>
> But I can't imagine how different it is from the `__attribute__((sentinel))`.
>
> So,why we need `__attribute__((sentinel(0,1)))`?
>
This is unrelated to Swift. That file is in clang; it's a test of clang's static analyzer.
__attribute__((sentinel)) is identical to __attribute__((sentinel(0, 0))). The difference between sentinel(n, 0) and sentinel(n, 1) has to do with the handling of the last named parameter before the variadic arguments.
(n, 0) means the last named parameter is not part of the null-terminated list; the required sentinel must come after the last named parameter.
(n, 1) means the last named parameter is part of the null-terminated list; passing null to the last named parameter will satisfy -Wsentinel.
n is the number of non-null arguments that must follow the null sentinel. This is used for functions like execle() which passes envp after the null at the end of argv.
--
Greg Parker gparker at apple.com <mailto:gparker at apple.com> Runtime Wrangler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160906/570ac57a/attachment.html>
More information about the swift-users
mailing list