Re: A question regarding C string functions

Liste des GroupesRevenir à l c 
Sujet : Re: A question regarding C string functions
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 03. Apr 2025, 08:29:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsldc8$28l7$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 02/04/2025 20:33, Kaz Kylheku wrote:

It gets more verbose and indented, but the null treatment is
consistently there.
 
In the current working draft for the future standard after C23, it says:
"""
Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call may be null pointers. On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters.
"""
And the change list includes :
"""
Allowed zero-length operations on null pointers.
"""
That sounds like if you call something like "strncpy" with a maximum length of 0, then null pointers are safe - if nothing is moved, copied, or searched, then the pointer is not dereferenced and the behaviour is defined.
It seems likely to me that this is the behaviour you would get with most current implementations of the library functions - but of course that is not something to rely on until you are using post-C23 standard tools.

Date Sujet#  Auteur
2 Apr 25 * A question regarding C string functions8Lew Pitcher
2 Apr 25 +* Re: A question regarding C string functions3Kaz Kylheku
2 Apr 25 i+- Re: A question regarding C string functions1Lew Pitcher
3 Apr 25 i`- Re: A question regarding C string functions1David Brown
3 Apr 25 +* Re: A question regarding C string functions3Tim Rentsch
3 Apr 25 i+- Re: A question regarding C string functions1Lew Pitcher
3 Apr 25 i`- Re: A question regarding C string functions1Ethan Carter
3 Apr 25 `- Re: A question regarding C string functions1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal