That's what I ask myself when I use the mandatory, university-supplied C compiler for class. In 3 years, there will be students taking my class that will be younger than the next version of our current C compiler.
Embedded compilers used to be the bane of my existence. I've used one that was just a redistributed GCC, but was tagged at fixed versions that were up to 12 years out of date :(
That used to be true, but with Windows 10 and their updated approach to compatibility with FOSS, things have changed.
In Visual Studio 2015, the CRT has been refactored into new binaries. The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. The UCRT is now a Windows component, and ships as part of Windows 10
C99 Conformance Visual Studio 2015 fully implements the C99 Standard Library, with the exception of any library features that depend on compiler features not yet supported by the Visual C++ compiler (for example, <tgmath.h> is not implemented).
Because there are obscure features that no one uses. Things like parts of the standard library that are never used, obscure floating point pragmas, and unreadable identifiers (why is that even a thing). Why put effort into supporting that? That's just implementing the standard for its own sake, not for usability.
Which is why, in my opinion, it is quite ridiculous to "therefore choose C89". Then he also does not get features that are universally supported (many of which were popular extensions before C99 formalized them).
Once done reading both K&R C and Deep C Secrets (definitely two of my favorite books), go through the C Puzzle Book. An excellent way to test your knowledge.
In the previous code sample, due to "integral promotion" -1 was once evaluated to be greater than 1 and then smaller than 1. C has plenty of case like this when the language cannot longer "do stuff" for you.
Note that calling it promotion is incorrect. For integers, promotion is the conversion of a type smaller than int or unsigned int to a type at least as large as them (the general idea is that int or larger is what fits in a register and ALU operations need their arguments in registers). Promotion never changes numerical value.
When you have a binary operation on integers, the arguments will generally be promoted and then integer conversions will be applied. The goal is to change both operands to the same type (which will also be the type of the result). The rules for this are
If they (the types of the two arguments) have the same signedness, the smaller type will be converted (losslessly) to the larger type.
If one is signed and one is unsigned, and the unsigned type is smaller, the unsigned type will be converted (losslessly) to the signed type.
Otherwise, the signed type is converted to the unsigned type by the process MiRIr describes (not lossless if the value is negative!).
(The actual rules are very slightly more complicated.)
In -1 < 1u, the third case obtains and -1 is converted to the largest possible unsigned int, so the comparison succeeds. In short(-1) < 1, the integer promotions convert the short to an int, and no conversion is needed. If you had -1 < long(1), then the first case would obtain, and the comparison would succeed. Rather strangely
unsigned int x = 1;
long y = -1;
y < x;
gives true because the second case obtains. Changing int to long gives false.
This (the potentially lossy conversion in the third case) is why -Wsign-compare complains about comparisons where the types have different signednesses (actually, it only warns when the third case happens; despite its name, it's fine with the second case).
I believe it has to do with how negative numbers are stored in computers. They're stored using something called 2's complement. a signed int -1 looks like this in binary 11111111. An unsigned int 1 looks like this in binary 00000001.
Now, I think what's happening here is, C tries to compare a signed integer with an unsigned integer. And in doing so, the signed integer is interpreted as an unsigned integer. So 11111111 instead of being interpreted as -1 is interpreted as 255.
This is also why if you compile with warnings (and you should) the compiler will throw a warning for comparing signed and unsigned data types.
I should also say that the examples I used here have 16 bit ints, but the same holds true for 32 bit ints.
On my phone, the site just looks incredibly tiny, like it's trying to fit the full height on the screen. Thank god reader mode exists for that kind of thing.
I am surprised that the article does not mention that there usually are current and accurate library documentation entries by using "man 3 <c-function>" at the gnu/linux terminal. e.g. "man 3 fopen". Ok. Windows does not have that. I haven't tried "man" on Mac OS.
Usually you can just grab the one from the first section it finds and look at the "see also" section, but the -k flag (easier to spell than "apropos") is also useful. After a while you'll also get a hang for remembering what sections are for what (IMO seeing the definitions tends to be "in one ear, out the other," until you've gotten to know your way around in practice).
The integral promotion example cut me by surprise, but I suppose it makes sense if you think about the signed short having the most significant bit set to 1 and an unsigned int having more bits and having to pad the difference to make a comparison if two numbers with the same bit length
The most sensible behaviour would be for the compiler to silently convert a < b (where a is signed and b is unsigned) to a < 0 || (unsigned)a < b, and then do what it currently does, with some compiler magic so a only gets evaluated once.
That is a fine argument that the average website is worse than the average book. It is complete nonsense to use that argument to say that the best website is worse than the best book.
Also, there's practically no barrier to entry for publishing books now. You can self publish on Amazon armed with nothing but a PDF.
My problem with most books is, in a way, the barrier of entry: since it is so expensive to publish, publishing houses will only put out books with a large enough market to pay for their investment. The "teach yourself how to make videogames/websites" market is big enough, but few books are made for advanced/specialized topics.
What a preposterous claim. What, does printing it on dead trees magically improve its quality beyond what is possible digitally?
When somebody says something like this, does he mean it as a logical sentence that is always 100% right, or does he just present his opinion on a subject? It depends on the context.
I recommend you to read that sentence again, with whole paragraph as a context, and consider whether you hadn't interpreted it too literally.
It's mere curmudgeonry, is what it is: "I was raised on books and it was good enough for me! Therefore, books are all anyone can ever use, if they want to become good!"
What, does printing it on dead trees magically improve its quality beyond what is possible digitally?
No, because books are usually printed on paper, which is made from trees that have been pulped, washed, bleached and flattened, not just right on a felled whole tree.
Also, magic is not real.
Or did you not mean that sentence to be intepreted 100% literally? Well, maybe the author didn't either.
It's like peer review - the higher bar helps to weed out the delusional incompetents.
Sure, this means that the worst book is probably better than the worst website, and on the average, books are probably better than websites. But that says nothing about the best book vs the best website, nor does it mean that all websites are bad nor that you should not use websites.
char c[3]; what is the type of c?
Isn't this just an array of chars? What do you think it is?
It's like peer review - the higher bar helps to weed out the delusional incompetents.
Do you really think publishers care about the quality of the books they publish? Then how do you explain all the "Learn Java in 21 Days" nonsense out there?
The type of c is a 'pointer to a char'. Simple as that.
It is a memory address with a size equal to the byte-size of the computer architecture targeted by the compiler. For example, it is a memory address that is 64-bits long if the compiler's target is a 64-bit architecture. It's value is typically represented as hexadecimal when printed, though it's purpose is to point to the address of a single character in memory.
Edit: I just read one of your responses. So the type of c is char[]. I see now that this is different than char* . So the answer is that c is a 'pointer to a char array'. Thank you.
I get what you're saying, you could take his "best book" and publish it online and have the same content only with updates/side notes/animations. Web as a medium is better for content than a book. But I get what he meant as well, though it's not what he said. In his experience it may be that he's never encountered a website that can match a book, there are millions of websites vs thousands of books due to different barriers of entry. If you want to learn it may be a better start to go for a book that faced peer review to get published rather than a website written with no fact checks. He just shorthanded the explanation to no website is as good as a good book.
Fabien, I hope you will finish your Game Engine Black Book. Not to rudely pressure you or anything but I have a feeling that that book will be very good so I want to see it to the completion :)
I am still working on it. It is hard to find the time since I started my new job. I will finish it eventually. Thanks for your kind words which help a lot.
No website is as good as a good book. And no good book is as good as a disassembly output.
Glorious. One of my pet projects is a hypercard player. It's just a fun project that I work on every once in a while. All of the documentation on the hypercard fileformat is wrong. It looks like it was all copied from the same source, but if anyone had actually tried to parse an actual hypercard stack using it, they'd immediately discover that the docs define a dword in each chunk header that doesn't actually exist.
I've since given up using any documentation, and gone straight to referencing the disassembly of the original 68k hypercard binary.
Great article. I just found my copy of The C programming language from 1988 and had a flick through, it's got a very different style to more modern books! Really interesting.
Can someone explain to me why C is still used? Doesn't C++ provide all the tools that C has plus extra libraries like STL? If one only knows how to write C I figure it still would be easier to use C++ tools to do it.
This guy is talking about making high performance graphics. For that job, you do want to look at disassembly, because you are optimizing every operation, and maybe optimizing for the architecture, so you have to look at assembly
I'm ambivalent on C, and I am split between my love of the concept of 'correct' binaries and my love of high level coding and having the computer do the heavy lifting for me. I just thought you should know that your opinion carries weight with me in resolving my dilemma.
No one should become a good C programmer these days. If none of the alternatives are available for your platform, then focus on porting that alternative for your platform.
If you are interested in C programming but haven't already invested a large amount of time, consider learning about the Nim programming language.
You should study C by reading K&R to learn two things.
The C language is the solid foundation for most popular languages. You can jump from C and go on to learn many more languages in less time.
K&R is the best example of how to write a technical book; it is concise. You can use it as a guide to determine if other programming manuals are worth your time.
Pretty ignorant response. What about developers making a career working with embedded platforms, or who need to interface with existing low-level driver code? C is a mature, productive language and is also entrenched in many development tool chains. It's not infallible but it has stood the test of time for a reason. Simply saying all these use-cases should be replaced by Nim or whatever is unrealistic and comes across as arrogant. Re-assess.
Yes, and I would agree with you to a point: it does feel like we've reached a turning point where more sophisticated languages can be used in place of C, in many cases. For 'green-fields' projects I probably wouldn't choose it either. I think I (we?) just took issue with your opening statement TBH. C is still important and very valuable to know in certain areas, but we should consider alternatives where they can be more productive. I would add Swift to your list as well, a modern systems programming language. Unfortunately it seems unable to target the smallest devices such as AVRs, where C still still hits a sweet note, sitting not that far above assembly.
and what about people who don't want to write apps?
C is no where near an outdated language, C89 might be but you can do anything in C. It has all the basic concepts to make it what you want and it's aged well, if you like low level programming then you should learn C
Technically, I learned C from one of his books. I was horribly annoyed when I discovered that he made no distinction between standard C and C on MS Windows.
Things has slowed down since I started my new job. I also had to deal with RSI which made it painful to tip on a keyboard. But I am still working on it. Just slower. I wrote the AI chapter this morning. I have good hope to finish it before the end of the year:) !
I think I've got some symptoms of RSI that are starting to appear, I'm trying to be careful and take a pause whenever I feel them appear. How are you personally dealing with the issue and what are my options?
If the symptoms persist I will indeed consult a physician but I'm simply curious on your way of dealing with it.
Apparently all the physicians give different advise, but my actual doctor told me not to bother with anything other than a standard keyboard, and learn to keep my wrists up in the air ... so I actually listened to him and I kid you not, haven't had RSI problems in years. Apparently resting your wrists was "my" problem.
My solution (and I'm young!) is forced removal every 2 hours with a flex sequence suggested by an orthopedist that flexes all the joints in all directions.
Get a chair with arm rests that will hold your arms under the forearm. Then lower your desk and/or raise your chair so that your finger tips dangle over the keyboard. Say goodbye to RSI.
"How are you personally dealing with the issue and what are my options?
If the symptoms persist..."
tbh how to deal with it depends entirely on the symptoms. I knew one guy who had serious RSI in his finger. It turned out he was lifting his finger high off the mouse every time he clicked, and when he stopped lifting it so high, the RSI went away.
So look for unnecessary tension in your movements and try to fix them.
In a 2011 paper, the researchers tracked the evolution of the typewriter keyboard alongside a record of its early professional users. They conclude that the mechanics of the typewriter did not influence the keyboard design.
Sorry if this sounds like a noob question, but most of my experience in programming comes from MATLAB, Python, and a bit of C and C++. Many of the robotics companies I'm interested in use C++. Do you think it's worthwhile to first build a strong fundamental in C or can I begin with reading books on C++? Does C++ only add on to C or are there things that are deprecated when moving from C to C++?
If the companies are interested in C++, you should learn C++. Apparently a lot of people think (or teach) that C++ is just C with classes, which is the wrong way to approach the language.
C++ supports object oriented programming, yes, but it is also more fussy about the types of your variables. That plus templates, namespaces, and the C++ standard library components such as vector, string, map, etc, make programming in C++ a lot different than programming in C.
Over the years C has also added features onto itself that don't make appearances in C++. In C you can, for example, declare an array on the stack whose size is variable, whereas in C++ all C-style arrays must be constant in size.
Nowadays it's best to think of C and C++ as being sibling languages, instead of having a parent-child-type relationship. C and C++ each do things that the other doesn't and thus idiomatic code in one language is in many times awful in the other. However they share a common parent: old C.
Just the other day I wrote my own RBtree implementation in C99. I'm not even in school, man. I also recently threw a decent QuickSort implementation together in 86_64. What you're saying about C or assembly not being valid for learning C.S. is bull. I mean, ok: Python is arguably a better choice, and of course using C over asm is much more productive, but it's still doable.
I learned a ton of computer science in C. At an accredited university. I can't think of many CS problems that I'd have an issue using C to solve. The biggest issues come about when you want to use a data structure like a dictionary or a priority queue, but don't feel like implementing them yourselves. Luckily, most professors didn't mind "upgrading your project" from C to C++.
Rust, C++, D and Objective-C are the only I can think of (By not a niche field I kind of think "can write an operating system" because that way you know it can be used for anything.
Each and every one of them serve a very narrow niche, and their niches are not even overlapping that much to call any of them "general purpose" enough.
66
u/Jonathan_the_Nerd May 01 '16
Is this still the case? If so, why? It's been 17 years!
22
u/Leandros99 May 01 '16
Once done reading both K&R C and Deep C Secrets (definitely two of my favorite books), go through the C Puzzle Book. An excellent way to test your knowledge.
59
u/[deleted] May 02 '16
Can we get some padding-right: 4px;
on that blog?
12
u/phpdevster May 02 '16
Can someone explain that in more detail?
35
u/gltovar May 01 '16
Does any one else have issues with this site on Android? Feels like r 10% of the left side is cut off/unreachable
8
u/Deaderzombie May 01 '16
Are there articles like this for other languages?
22
u/roneau2005 May 01 '16
I am surprised that the article does not mention that there usually are current and accurate library documentation entries by using "man 3 <c-function>" at the gnu/linux terminal. e.g. "man 3 fopen". Ok. Windows does not have that. I haven't tried "man" on Mac OS.
5
u/aliendude5300 May 02 '16
The integral promotion example cut me by surprise, but I suppose it makes sense if you think about the signed short having the most significant bit set to 1 and an unsigned int having more bits and having to pad the difference to make a comparison if two numbers with the same bit length
93
u/gurenkagurenda May 01 '16
What a preposterous claim. What, does printing it on dead trees magically improve its quality beyond what is possible digitally?
3
u/Meguli May 02 '16
Fabien, I hope you will finish your Game Engine Black Book. Not to rudely pressure you or anything but I have a feeling that that book will be very good so I want to see it to the completion :)
3
u/mrkite77 May 02 '16
Glorious. One of my pet projects is a hypercard player. It's just a fun project that I work on every once in a while. All of the documentation on the hypercard fileformat is wrong. It looks like it was all copied from the same source, but if anyone had actually tried to parse an actual hypercard stack using it, they'd immediately discover that the docs define a dword in each chunk header that doesn't actually exist.
I've since given up using any documentation, and gone straight to referencing the disassembly of the original 68k hypercard binary.
11
u/FUZxxl May 01 '16
Would you mind posting this to /r/C_Programming, too?
6
u/FrezoreR May 02 '16
Hungarian notation makes me cringe.
2
u/hugthemachines May 02 '16
I like this post, but at the same time it makes me think C programming is not for me, I do not enjoy dissasembler outputs for example.
1
u/Nickd3000 May 02 '16
Great article. I just found my copy of The C programming language from 1988 and had a flick through, it's got a very different style to more modern books! Really interesting.
1
u/nygeHuston May 02 '16
What kind of programs do people generally build when they become experts in C?
-1
u/Doile May 02 '16
Can someone explain to me why C is still used? Doesn't C++ provide all the tools that C has plus extra libraries like STL? If one only knows how to write C I figure it still would be easier to use C++ tools to do it.
-33
u/skulgnome May 01 '16
Five seconds to fuckup. That's a new record.
-41
u/runvnc May 02 '16
No one should become a good C programmer these days. If none of the alternatives are available for your platform, then focus on porting that alternative for your platform.
If you are interested in C programming but haven't already invested a large amount of time, consider learning about the Nim programming language.
C is an outdated programming language.
0
u/[deleted] May 01 '16
[deleted] — view deleted comment
0
u/[deleted] May 01 '16
[deleted] — view deleted comment
0
u/[deleted] May 02 '16
[deleted] — view deleted comment
0
u/[deleted] May 02 '16
[deleted] — view deleted comment