I'm glad to see that setjmp() and longjmp() are still allowed. I'm just kidding by the way. For those C programmers who haven't encountered these before, it is a powerful way to do a "goto" in C. Powerful in the sense that you can jump anywhere, not limited to the same function. If it's used at all these days, it's used for exception handling. More info: https://en.wikipedia.org/wiki/Setjmp.h
Banned C standard library functions in Git source code
311–320 of 329 posts
Re: Banned C standard library functions in Git source code
#312Earlier quoted context omitted.
The thing you are pointing to could have its length prefixed. I've always assumed that this isn't the case because nobody could commit to the size of the length prefix. Is it string8, string16, string32, or string64? Using a sentinel value to denote length is less opinionated and more portable.
And also unbeatable in memory efficiency.
Re: Banned C standard library functions in Git source code
#313Re: Banned C standard library functions in Git source code
#314Looks like Git has its own string type: https://github.com/git/git/blob/master/strbuf.h https://github.com/git/git/blob/master/strbuf.c See this for the story of why strncpy/strncat are insecure: https://en.wikipedia.org/wiki/C_string_handling#Replacements
Like essentially all C programs.
while (*s1 && n--) {
*s2++ = *s1++;
}
*s2 = '\0';
it is, then.Re: Banned C standard library functions in Git source code
#315Earlier quoted context omitted.
I had only seen them in the context of userspace threading. I wonder what mainstream libs use them. Do you know of any?
Generators are a subset of coroutines, and coroutines are useful in lexing and parsing.
Re: Banned C standard library functions in Git source code
#316Earlier quoted context omitted.
Fortunately, 99% of developers, like 99% of drivers, are better than average.
> 99% ... are better than average. I'm thinking there's a flaw in your mathematics...
> 70% of respondents say they are above average
Re: Banned C standard library functions in Git source code
#317Earlier quoted context omitted.
Like essentially all C programs.
That was my first thought. No strncpy? Ok, while (*s1 && n--) { *s2++ = *s1++; } *s2 = '\0'; it is, then.
Re: Banned C standard library functions in Git source code
#318Re: Banned C standard library functions in Git source code
#319Earlier quoted context omitted.
Fortunately, 99% of developers, like 99% of drivers, are better than average.
> 99% ... are better than average. I'm thinking there's a flaw in your mathematics...
Re: Banned C standard library functions in Git source code
#320Earlier quoted context omitted.
I've always wondered why goto is actually considered harmful. I really should read the original paper by Djikstra...
Read David Tribble's "Go To Statement Considered Harmful: A Retrospective" instead: http://david.tribble.com/text/goto.html . It contains the entire text of Dijkstra's paper and goes over its meaning in a modern context on a paragraph-by-paragraph basis. It's very well written and makes clear the "encourages spaghetti code" argument, while true at the time, applied in a era where basic control flow constructs that we…
int parse(void)
{
Token tok;
while ((tok = gettoken()) != END)
{
while (!shift(tok))
if (!reduce(tok))
return ERROR;
}
return ACCEPT;
}
I will say that any language without goto, or where the use of goto is discouraged, should at least provide guaranteed tail-call elimination as an alternative. In this case the gotos could easily be converted into loops, but not every algorithm is so accommodating.