I've gone through a lot of exercises[0][1] from this site especially on how to implement a linked list in C. The time spent from the tutorial was absolutely worth while. I feel happy and satisfied with my self after solving one problem at a time.
For those who already know the syntax of C but wanted to learn more, the links I mentioned is a good exercise and opens up a lot of possibilities on what you can implement. You'll soon be able to realize the importance of linked list and why you'll want to use a linked list instead of just plain arrays.
My favourite language is Lisp, in which I use "linked" lists all the time, but I never use them in C. Use of lists without a garbage collector and either dynamic typing (as in Lisp) or strong static typing (as in Haskell) is a pain, and C has none of these built in. This means that, in C, you need to allocate memory every time you add something to your list, and hold the pointer to it in order to free it later. You also need to keep track of which types are stored, and where.
If your problem requires a lot of list processing, use a language more suitable for it. Otherwise, use extensible arrays, which are easy to implement in C.
conceit also pointed out that lists also increase the likelihood of cache misses, which slows down the program a little bit. Many C programmers care about that. I don't share their priorities - it is important to me, but less so than correctness, ease of programming (allowing more time for exploration and finding a more efficient algorithm), and response times.
I want to love ddd, really I do, conceptually it is awesome and beautiful. In practice it is (IME) buggy (almost) to the point of uselessness. It's been a couple of years since I last used it, but it was last updated around 2009 :-(
This is an enjoyable comment section (rare to say). The arguments about the pronunciation of the char keyword is all part of being C programmers. This is great. :-)
strlcpy returns offset of dst + len of src which requires strlen(src) which isn't optional and sort of sucks imo.
Something very similar but that doesn't do strlen(src) such as https://godbolt.org/g/Etpuhz would be better.
The "C Programming Cleverness and Ego Issues" is a good bit of advice:
> Build programs that do something cool rather than
programs which flex the language's syntax. Syntax -- who cares?
Otherwise, I'd never heard of/seen the `#pragma once` preprocessor directive. (Not that I do that much C programming!) How common is it to use this over include guards?
I've always pronounced it as 'care', not because of how the identifier is spelled but because it's the first syllable of the word 'character'.
I don't think there's a consensus between car/char/care, though, even among C's creators. But if there was, I would vote for 'care'.
I always thought SQL was another weird one. When discussing the language itself, you can say 'sequel' or 'ess queue ell' interchangeably, but when referring to a database that has "SQL" in its name, there is a DB-specific one true pronunciation:
* SQL Server: 'sequel server'
* PostgreSQL: 'post gress queue ell'
* SQLite: 'sequel light'
* MySQL: 'my ess queue ell'
There's no complete consensus on any of those- just a preponderance of one, or an officially endorsed pronunciation in a FAQ someplace.
I've also heard 'my squeal' for MySQL, breaking out of the 'sequel'/'ess queue ell' duopoly altogether.
Bollocks, pronounced char as in "char". I did not know this was even in dispute. Not that i care how anyone else pronounces it, i just thought it was blindingly obvious since we already have an English word spelled exactly the same as what we use in code to declare the thing.
I too pronounce it that way, since I learned C from books and just read it as it was printed.
I later noticed some people do pronounce it "car" which just seems odd. Why change it, if it doesn't save a syllable? It's not a truncation of how "character" is said either, because that's a different vowel sound.
Saying 'car' causes problems when learning C++, because all OOP examples on composition start "Car has-an Engine".
[+] [-] e19293001|10 years ago|reply
For those who already know the syntax of C but wanted to learn more, the links I mentioned is a good exercise and opens up a lot of possibilities on what you can implement. You'll soon be able to realize the importance of linked list and why you'll want to use a linked list instead of just plain arrays.
[0] - http://cslibrary.stanford.edu/103/LinkedListBasics.pdf
[1] - http://cslibrary.stanford.edu/105/LinkedListProblems.pdf
[+] [-] DonaldFisk|10 years ago|reply
If your problem requires a lot of list processing, use a language more suitable for it. Otherwise, use extensible arrays, which are easy to implement in C.
conceit also pointed out that lists also increase the likelihood of cache misses, which slows down the program a little bit. Many C programmers care about that. I don't share their priorities - it is important to me, but less so than correctness, ease of programming (allowing more time for exploration and finding a more efficient algorithm), and response times.
[+] [-] conceit|10 years ago|reply
[+] [-] mynameisnoone|10 years ago|reply
Here's a proper reference on C99 and C11:
http://en.cppreference.com/w/c
And see also reallocarray.
[+] [-] dave84|10 years ago|reply
[+] [-] partycoder|10 years ago|reply
[+] [-] stevetrewick|10 years ago|reply
[+] [-] eplanit|10 years ago|reply
[+] [-] unknown|10 years ago|reply
[deleted]
[+] [-] thatsadude|10 years ago|reply
[1] http://www.literateprogramming.com/ctraps.pdf
[+] [-] aninteger|10 years ago|reply
[+] [-] nwmcsween|10 years ago|reply
[+] [-] _kst_|10 years ago|reply
[+] [-] Xophmeister|10 years ago|reply
> Build programs that do something cool rather than programs which flex the language's syntax. Syntax -- who cares?
Otherwise, I'd never heard of/seen the `#pragma once` preprocessor directive. (Not that I do that much C programming!) How common is it to use this over include guards?
[+] [-] exDM69|10 years ago|reply
Not very. It works in Microsoft's C compiler but can't be relied on elsewhere.
[+] [-] camperman|10 years ago|reply
Pronounced 'car'? Bollocks. Pronounced char as in charred.
[+] [-] mwfunk|10 years ago|reply
I don't think there's a consensus between car/char/care, though, even among C's creators. But if there was, I would vote for 'care'.
I always thought SQL was another weird one. When discussing the language itself, you can say 'sequel' or 'ess queue ell' interchangeably, but when referring to a database that has "SQL" in its name, there is a DB-specific one true pronunciation:
* SQL Server: 'sequel server'
* PostgreSQL: 'post gress queue ell'
* SQLite: 'sequel light'
* MySQL: 'my ess queue ell'
There's no complete consensus on any of those- just a preponderance of one, or an officially endorsed pronunciation in a FAQ someplace.
I've also heard 'my squeal' for MySQL, breaking out of the 'sequel'/'ess queue ell' duopoly altogether.
[+] [-] drivebyops|10 years ago|reply
https://www.youtube.com/watch?v=de2Hsvxaf8M&t=2m35s
[+] [-] _kst_|10 years ago|reply
C Infrequently Asked Questions #19.26, https://www.seebs.net/faqs/c-iaq.html
[+] [-] mikestew|10 years ago|reply
[+] [-] broodbucket|10 years ago|reply
[+] [-] mbreese|10 years ago|reply
I've always pronounced "char" as "car". Dunno why, I learned C from a book, so no one got to tell me I was wrong.
[+] [-] robert_tweed|10 years ago|reply
I later noticed some people do pronounce it "car" which just seems odd. Why change it, if it doesn't save a syllable? It's not a truncation of how "character" is said either, because that's a different vowel sound.
Saying 'car' causes problems when learning C++, because all OOP examples on composition start "Car has-an Engine".
[+] [-] corndoge|10 years ago|reply
[+] [-] teddyh|10 years ago|reply
> char: /keir/, /char/, /kar/, n.
[+] [-] unknown|10 years ago|reply
[deleted]
[+] [-] unknown|10 years ago|reply
[deleted]
[+] [-] conceit|10 years ago|reply
[+] [-] rootbear|10 years ago|reply
[+] [-] cbd1984|10 years ago|reply
[+] [-] sklogic|10 years ago|reply
[+] [-] cbd1984|10 years ago|reply
[+] [-] _kst_|10 years ago|reply
But as of 2003, support for C99 wasn't very widespread, so omitting <stdint.h> was understandable.
[+] [-] npx|10 years ago|reply
I'd love to see an updated version.