Re: strncmp(3) in the SYNOPSIS
From: Florian Weimer <hidden>
Date: 2025-06-05 15:28:34
* Alejandro Colomar:
Hi Florian, On Thu, Jun 05, 2025 at 04:53:02PM +0200, Florian Weimer wrote:quoted
Somewhat related: This syntax is currently used for inputs that can be either strings or arrays. Two examples: size_t strnlen(size_t maxlen; const char s[maxlen], size_t maxlen); int strncmp(size_t n; const char s1[n], const char s2[n], size_t n); Obviously, we want strncnmp(subject, "prefix", 6) to be valid independently of the length of the subject string,I'm not sure I understand your statement. It assumes that the subject is a string, which it need not be. [[gnu::nonstring]] char subject[7] = "asdfghi"; strncmp(subject, "prefix", 6);
My point is that *if* it is a string, it can be arbitrary long. It does not have to contain at least five characters, it can be shorter. These two choices are valid: subject is a string subject is an array that is at least six bytes long They overlap, but both options are needed. For example, "?" is not an array that is at least six bytes long. Thanks, Florian