News for hackers. Stuff that matters.
Re:To become a good C programmer (2011) by ternaryoperator on Friday February 14, 2020 @03:41PM (#22330184)
In the 90s, most seriouc C programmers knew about these books. They were the core books most devs relied on and referred to. They're all good.

I disagree with this comment: "No website is as good as a good book. And no good book is as good as a disassembly output."

There are many websites today that are excellent. And there are many websites that cover obscure topics not found in books.

Finally, I think it's important to move past C89 to at least C99. I realize in 2011 (the date of this post), that was less feasible. But today, there is little reason for most projects not use the advances found in C99.

Re:To become a good C programmer (2011) by hazeii on Friday February 14, 2020 @04:25PM (#22330554)
Personally (3 decades+ journeyman C), I find lot of the advances are often about trying to get people out of bad practices (e.g. stdint.h in C99 to fix portability issues between 32 and 64 bit).
Re:To become a good C programmer (2011) by xscott on Friday February 14, 2020 @05:30PM (#22331044)
The names in stdint.h are ok, but the way they play with library functions like printf() and scanf() is not so great. Given an int64_t value x, each of these works on some platforms and is wrong on another:

    printf("here's your int64_t:  %ld\n", x);
    printf("here's your int64_t:  %lld\n", x);
And the portable way using inttypes.h is really ugly:

    printf("portably int64_t:  %" PRId64 "\n", x);
There's another religious argument to be had over size_t vs ssize_t, but that can wait :-)
Re:To become a good C programmer (2011) by madmax96 on Friday February 14, 2020 @05:38PM (#22331107)
Then there’s the perennial problem of missing format specifiers for POSIX types like pid_t. Although you could argue that POSIX should mandate macros to appropriately handle them, the root problem is the same.

The default integer types have not aged well...

Re:To become a good C programmer (2011) by xscott on Saturday February 15, 2020 @01:05AM (#22333601)
> missing format specifiers for POSIX types like pid_t

This bothers me less because I can always cast it up:

    fprintf(logfile, "pid: %lld", (long long)pid);
Technically not portable, but find a platform with PIDs where this breaks. You can count on long long being at least 64 bits, and I think it'll be a while before we need 128 bit process IDs. :-)

> The default integer types have not aged well...

To me, the real pisser is that every compiler copped out and decided to leave int at 32 bits when the architecture advanced to 64 bits. Part of the reason for compilers exploiting "signed can't overflow" is so they can work around for loops with 32 bit int variables, and this has ugly consequences because most of the conversion rules in C are defined with respect to int.

And honestly, Microsoft should burn for leaving long at 32 bits.

Re:To become a good C programmer (2011) by jacobush on Saturday February 15, 2020 @06:00AM (#22334540)
On Amiga, long was 32 bit and int 16 bit and that was a long time ago, when Microsofts int was also 16 bit. So they already shifted it up once. (Going from DOS to Win32 I guess.)
Re:To become a good C programmer (2011) by Gibbon1 on Saturday February 15, 2020 @04:05PM (#22337958)
The concept of int hasn't aged very well. People think it's fine because it's always 32 bits on their machine. Go recompile on a machine where it's 16 bits and see how that works out.
Re:To become a good C programmer (2011) by earenndil on Friday February 14, 2020 @06:20PM (#22331436)
What I wonder is, why didn't they add new *printf functions? So you could say 'printf("int64: %d64", x)'
Re:To become a good C programmer (2011) by boomlinde on Saturday February 15, 2020 @08:56AM (#22335300)
Backward compatibility. Your example would impose additional constraints on the %d specifier that would likely break existing code. What if you want an int immediately followed by literal ”64”?
Re:To become a good C programmer (2011) by earenndil on Saturday February 15, 2020 @06:26PM (#22338763)
Oops, I typoed. I said 'new *printf functions'; the example was supposed to be 'printf2("int64: %d64", x)'
Re:To become a good C programmer (2011) by boomlinde on Monday February 17, 2020 @05:24PM (#22351464)
I see! That would make more sense, but I still think the inttypes.h macros are a sufficient solution. Implementers and standards influencing users probably aren't too keen on another formatting language when you can implement it as macros that only take another few characters to use.

    printf2("int64: %d64", x);
for example isn't significantly shorter than

    printf("int64: %" PRId64, x);
Perhaps it's easier to read, but when you have to support both, and you're more likely to run into the latter than the former anyway, I think it just adds cognitive overhead to have to consider which formatting language is being used.
Re:To become a good C programmer (2011) by VonChair on Friday February 14, 2020 @04:34PM (#22330625)
I think it's important to push forward with getting people out of bad habits. In a lot of cases, the only way to do that is to force it. I don't often agree with things Apple does, but their forcing people to use x64 is similar to this I think.
Re:To become a good C programmer (2011) by imron on Friday February 14, 2020 @04:21PM (#22330522)
> But today, there is little reason for most projects not use the advances found in C99.

Does visual studio support c99 yet? Last I heard MS wasn’t interested in supporting it.

Re:To become a good C programmer (2011) by xeeeeeeeeeeenu on Friday February 14, 2020 @06:53PM (#22331661)
It supports most of it. Useless stuff like VLA is still uninmplemented though.
Re:To become a good C programmer (2011) by polyphonicist on Saturday February 15, 2020 @03:40AM (#22334080)
Why is VLA useless?

Why was it added to C99?

Re:To become a good C programmer (2011) by flohofwoe on Saturday February 15, 2020 @07:10AM (#22334762)
Because even C isn't free from the occasional misfeature slipping into the standard. VLAs come with a lot of caveats (e.g. available stack size being limited and opaque, no sizeof() support, etc).

VLAs were made optional in C11, so it's better not to use them at all for portable code.

Re:To become a good C programmer (2011) by zelly on Friday February 14, 2020 @05:28PM (#22331031)
You can use clang on VS
Re:To become a good C programmer (2011) by hazeii on Friday February 14, 2020 @04:27PM (#22330569)
Really? No longer an MS user but occasionally my code gets ported to Windows so would like to know more.
Re:To become a good C programmer (2011) by dfox on Friday February 14, 2020 @04:42PM (#22330696)
MSVC in C mode is essentially C89 plus extensions needed to compile C++/C99-isms present in Windows SDK and DDK headers. And Microsoft seems to be mostly interested in whether the compiler is able to build NT kernel and drivers and nothing much else.
Re:To become a good C programmer (2011) by nwellnhof on Saturday February 15, 2020 @03:25PM (#22337727)
That's not true for quite some time. Visual Studio 2013 added many C99 features that aren't in C++ like compound literals or designated initializers.
Re:To become a good C programmer (2011) by flohofwoe on Saturday February 15, 2020 @07:12AM (#22334766)
The only notable C99 features not supported on the MSVC C compiler are: (a) VLAs, and (b) type-generic macros. The distinction between the MSVC C and C++ compiler is important though. The MSVC C++ compiler doesn't support any C99 features.
Re:To become a good C programmer (2011) by anonsivalley652 on Friday February 14, 2020 @10:00PM (#22332852)
Nuance is needed. Multiple sources form the overall picture. I found that doing hard things in an embedded or conventional shipped product team is the best way to learn, and that working with effective people who used a particular language reasonably defensively and obviously for maintainability contributed the most code value.

For example, I taught myself Pascal, C, C++, assembly and Java (badly) before attending undergrad. The good thing about the ugrad program I had was that there were SGI, HP-UX, Solaris and Linux boxes such that writing portable C was essential.. you couldn't turn in a project if make didn't work on every platform because they wouldn't say which one they would use ahead-of-time. Then, I had an embedded internship at GPS manufacturer to work on 900 Mhz and 2.4 GHz radio firmware where a C++ subset was used on a codebase that spanned about 100 products. Also, lots of refactoring test/flashing tools was required because of commented-out code remnants were checked-in and 2000-line megafunctions because interns just banged-out code without any enforced coding standards.

Re:To become a good C programmer (2011) by fao_ on Friday February 14, 2020 @04:40PM (#22330675)
> And there are many websites that cover obscure topics not found in books.

Yup. Are there any books covering the same content that ctyme does? (http://www.ctyme.com/intr/int.htm)

Re:To become a good C programmer (2011) by pansa2 on Saturday February 15, 2020 @06:42AM (#22334680)
Ah, the famous “Ralph Brown’s Interrupt List”. It was actually published as a book: https://www.amazon.com/PC-Interrupts-Programmers-Reference-T...
Re:To become a good C programmer (2011) by markus_zhang on Saturday February 15, 2020 @09:34PM (#22339478)
just curious. this is not relevant nowadays right?
Re:To become a good C programmer (2011) by fao_ on Monday February 17, 2020 @05:01PM (#22351251)
It's relevant for any computer with a BIOS, it's relevant for the coreboot project (although these days in diminishing value).
Re:To become a good C programmer (2011) by markus_zhang on Tuesday February 18, 2020 @10:49AM (#22356855)
Agreed. I need to get some time-off/tech resort to study the fundamentals.