Re: Buffer contents well-defined after fgets() reaches EOF ?

Liste des GroupesRevenir à cl c 
Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 16. Feb 2025, 04:48:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vorn65$efhq$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 15.02.2025 18:53, Michael S wrote:
On Fri, 14 Feb 2025 21:02:19 +0100
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
 
On 14.02.2025 20:38, James Kuyper wrote:
>
As with several of the string processing functions, I think fgets()
would be better if it returned a pointer to the end of the data
that was read in, rather than to the beginning. 
>
Yes, that's another option. The language designer have to decide which
behavior is more useful. There's pros and cons, IMO.
 
IMHO, there are no cons.

If you think so.

Returning pointer to the end of data is very obviously superior.

I seem to recall to have had uses for both variants in the past. (Not
that it would have made a big difference.)

 
On the minus side
would be that the origin of the string gets lost that way.
 
Huh?
How could you lose something you just passed to the function?

For example if you use idioms like  s = str...(t++, ...) .

In most typical code, it's not even a complex expression or pointer,
but name of array.

I really don't want to argue with you about what is "The Best" design.

Personally I took advantage of how it's actually in "C" defined, and I
also occasionally missed the other design variant in some other cases.
(No design variant would have prevented me from "working around" the
effects of the missing one.)

And the "C" lib designers are not stupid; I'd think they had considered
what interface they implement. (Just speculating here of course.)

Janis

 
(Of course
you can adjust your code then to keep a copy. But any way implemented,
you need to adjust your code according to how the function is
defined.)
>
 
 


Date Sujet#  Auteur
8 Apr 26 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal