Read dynamic string

T

Toni Uusitalo

those said:
in comp.lang.c i read:

i elided most of the code -- sometimes this is a mistake, though i hope not
-- only the bits with nits remain.




int makes some sense, but i happen to prefer size_t as there is no meaning
in a negative length or offset in this code.

char *rfg(FILE * f, size_t l) {

also, this is now a very short name to have with external linkage. i would
probably change to internal linkage, or rename it rfgets_r -- heh, perhaps
both.

I would change its name to wof (write-only function)
(http://en.wikipedia.org/wiki/Write-only_language)
;-)

Well maybe I'm just jealous cos I couldn't come up with something as
clever as this function ;-)

with respect,
Toni Uusitalo
 
D

Daniel Fischer

those who know me have no need of my name!

what if the malloc fails? (the cast just to do the arithmetic is ugly
enough to want a change, even though it is valid -- as long as malloc
doesn't fail.)

One could argue that if malloc fails, writing to 0+l results in
fail-fast-by-segfault behaviour :)

But I guess you're right.


Daniel
 
R

Richard Bos

Daniel Fischer said:
those who know me have no need of my name!


One could argue that if malloc fails, writing to 0+l results in
fail-fast-by-segfault behaviour :)

_May_ result in fail-fast-by-segfault behaviour. May also, e.g., result
in fail-late-and-disastrously-by-overwritten-interrupt-vector behaviour.

Richard
 
F

Flash Gordon

Daniel said:
those who know me have no need of my name!


One could argue that if malloc fails, writing to 0+l results in
fail-fast-by-segfault behaviour :)

One could argue that, but one would not be right on all systems.
But I guess you're right.

He is indeed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top