Live data from Hacker News

Effective C: An Introduction to Professional C Programming

nostarch.com

91–100 of 109 posts

Re: Effective C: An Introduction to Professional C Programming

#91
post #59

Earlier quoted context omitted.

Exactly! To be blunt, knowledge of C gives you "programming cachet" like no other language.

I already have enough "programming cachet" with C++.

If you know C++, you know C (ignore dark corners and changes in later C standards). C++ is first and foremost a "better C" and only later everything else.

Re: Effective C: An Introduction to Professional C Programming

#92
post #81

Earlier quoted context omitted.

Don't jinx it! If this can get the non-C programmers to learn and understand the usefulness of a simple, minimal and direct language ("modern" languages are just too bloated), it is well worth it. I have said it before and say it again; C will allow you to program everything from itty-bitty MCUs to honking server machines. It is also the de-facto universal "glue" language and its real-world benefits far outweigh any…

Glue language aside (which arguably is a lot more true of unices than other platforms), I'd argue Forth might make a better language / minimal environment for learning the low-level parts of a computing system. It's got interactivity (bundled compiler/interpreter in one system), a large number of implementations (possibly more supported CPUs than C++, but that might be more due to its age), and a Forth system is easi…

May be true. However, my point was that C is everywhere and you just cannot escape it. Knowledge of this one language allows you to program real-world high-level applications to low-level systems (eg. OS/Compilers etc.) and everything in-between.

Given the proliferation of processors everywhere, it is of immeasurable value to a programmer to become familiar with one "universal" language/runtime/toolchain so that he can program literally anything. It simplifies "incidental complexity" (avoids "tower of babel") which is key to getting things done.

Re: Effective C: An Introduction to Professional C Programming

#93

I started learning C at the start of this year by going through K&R and Understanding and Using C Pointers. I will likely pick this is up, it looks good and I really like No Starch Press books. Does anyone have pointers on where to start with actual embedded programming? I have a couple Arduinos and RPis laying around, but I'm wondering if there are more 'real' ways to do it.

I can recommend the following for Embedded Programming;

* Michael Pont's Embedded C and Patterns for Time-Triggered Embedded Systems (PTTES). They are chock full of invaluable C code (for 8051); in particular, beg, borrow or steal PTTES (free pdf available). Also checkout his other books and his company SafeTTy Systems.

* Make: AVR programming by Elliot Williams teaches you to directly program the ATmega328P on a Arduino Uno.

* Introduction to Embedded Systems: Using Microcontrollers and the MSP430 by Jimenez, Palomera et al. is an excellent textbook explaining each hardware aspect of an embedded system and how to program them.

Note: All the above are for bare-metal embedded programming. For Embedded Linux on RPi, i suggest Exploring Raspberry Pi: Interfacing to the Real World with Embedded Linux by Derek Molloy.

Re: Effective C: An Introduction to Professional C Programming

#94

Can any more experienced C developers give an opinion on the author/contents of this book? I'm a Python/Julia developer starting to learn C. I have K&R already, and Test Driven Development for Embedded C (Grenning). I did order 'Modern C' by Gustedt but the publisher never delivered to Waterstones so they had to cancel the order (about 6 months ago, book still unavailable from Waterstones as of today).

Looks quite reasonable. I'm hopeful for a better introductory C text[1]. The author has plenty of street cred, the material covered looks good.

K&R is a good reference, but not good for learning the language IMO.

1: I love Plum's books (starting with learning to program in C), but can't recommend them since the language has changed so much in the 37 years since it came out.

Re: Effective C: An Introduction to Professional C Programming

#95

Earlier quoted context omitted.

Not to be rude to the author but what makes him the best person to be writing modern C books?

So it's hard to say that I'm the best person to write a modern C book. A slightly lower bar might be, am I the best person who has actually written a modern C Book? Resume-wise, I've been writing C code since 1985, and I've been an expert on the C Standards Committee (WG14) since 2004. I've written two prior books on C Programming including "Secure Coding in C and C++" and "The CERT C Coding Standard". I also teach S…

Oh, a standards committee member! We have requests...

Now that C allows mixing variable declarations in with statements, it becomes annoying that variable declarations can not have labels. This hits particularly hard with the switch/case, but can also apply with ordinary named labels. The syntax to work around this defect is ugly.

The gcc extension for case ranges is really valuable.

Setting the sign bit via a cast should not cause undefined behavior. (for example, going from uint32_t to int32_t) It should just work in the obvious way. Avoiding the problem requires extremely strange code.

I'd like a way to prevent arrays from being replaced by pointers. Assignment could work. Sometimes I really want to pass an array to a function, and I don't mind if that means a megabyte is copied into the function args on the stack. Sometimes I really want to force the huge copy, and other times I'd rather have the compiler keep it in the caller's frame (but callee can mangle it unless it is const) and just pretend that the callee got more than a pointer. Array dimensions need to survive. The callee's prototype should be able to demand specific dimensions or receive them as variables, and the caller should be able to pass a portion of a larger array

The default function parameters of C++ would be useful. The UNIX API for open() would be best done this way, allowing a prototype without the need for stdarg. There doesn't seem to be any reason why default parameters would have to be at the end; a pair of adjacent commas in the middle is a fine way to indicate that the default is to be used for that missing parameter.

It's time to standardize bitfield layout so that bitfields can be used in portable code for purposes like assemblers and disassemblers. (in other words, not for purposes like access to MMIO registers) Microsoft and GNU compilers are already quite compatible on x86_64, so that would be the basis of standardization.

When a bitfield happens to have the size and alignment of a normal integer type, it should be possible to take the address. The resulting type would be a pointer to the integer type of lowest rank having the correct size.

Anonymous unions and structs would be valuable in all scopes, including at file level. This would allow careful data organization to save space, improve cache locality, prevent undesired cache line aliasing, or allow the intentional aliasing of types. Current technology typically involves abuse of the linker, which is well outside the C language.

Being able to do something like an #include, but with a blob of binary data, would be helpful for initializing big arrays. Current practice is to have build scripts convert binary files to C, to have the linker do it, and to rely on assemblers with the capability. None of that is nice to use.

So that we don't have to invoke m4 or do nasty things with recursive macros, the preprocessor could support loops.

There are a few gcc extensions that make macros far more reasonable, including statement expressions and typeof. Add those.

Re: Effective C: An Introduction to Professional C Programming

#96
post #59

Earlier quoted context omitted.

I already have enough "programming cachet" with C++.

If you know C++, you know C (ignore dark corners and changes in later C standards). C++ is first and foremost a "better C" and only later everything else.

I can also add Object Pascal, Modula-2, Ada and plenty of others to the list, I just felt lazy and typed only C++.

Re: Effective C: An Introduction to Professional C Programming

#97
post #4

Earlier quoted context omitted.

For 272 pages written by probably the best person to be writing modern C books, from a small publisher who is known for quality books, sixty dollars doesn't sound unreasonable at all

Thank you. When our authors ask how long their book should be I always say: Long enough to cover the subject, short enough to keep it interesting. My company is called No Starch Press for a reason. Think of the word starch as a nicer way to say "BS", as in No BS Press. There's a lot of work behind these pages as with all of our books. Unlike any publisher in this field we have several people who read and craft every…

Would you be interested to launch translations of some of your books? I would love to make these technical books available in French and Esperanto.

I know the Rust book is already translated in some languages. I even started the Esperanto translation myself[1], but had other priorities in the mid time. Doing that in spare time doesn't help to accelerate the process, but I already achieved the translation of the Lua reference manual this way.

If you are interested, just send me an email through mathieu at culture-libre dot org, or reply to this message with some instruction on which canal you would prefer to use.

[1] https://github.com/psychoslave/Rust-libro [2] https://www.mediawiki.org/w/index.php?title=Extension:Scribu...

Re: Effective C: An Introduction to Professional C Programming

#98

I started learning C at the start of this year by going through K&R and Understanding and Using C Pointers. I will likely pick this is up, it looks good and I really like No Starch Press books. Does anyone have pointers on where to start with actual embedded programming? I have a couple Arduinos and RPis laying around, but I'm wondering if there are more 'real' ways to do it.

Check out this awesome course cs107e (http://cs107e.github.io/) from Standford. It will guide you to build a complete os from scratch in Raspberry Pi.

Re: Effective C: An Introduction to Professional C Programming

#99

I started learning C at the start of this year by going through K&R and Understanding and Using C Pointers. I will likely pick this is up, it looks good and I really like No Starch Press books. Does anyone have pointers on where to start with actual embedded programming? I have a couple Arduinos and RPis laying around, but I'm wondering if there are more 'real' ways to do it.

A good and motivational project imo can be to buy a simple sensor board for the Arduino, and write a driver yourself for it (even if drivers exist). Pick a simple sensor - some will require you to do all kinds of hoops and loops, but others are more like "startup, trigger sensor read, read out".

For this part, it's also fun to have a logic analyzer (starts at about 10 bucks) to see the change in code manifest on physical pins. It's also helpful to see that what you think you are doing, is actually happening. Eg, the SPI Chip select pin may be inverted (high when should be low and vice versa).

Then start off with a simple program that does init, and periodically read the sensor. Perhaps adding thresholds that trigger eg a LED. Then you can extend this to pipe over serial port to the rpi and push it to some server of your choice (eq mqtt), or display on a local webserver dashboard.

Go with sensors that are ordinary SPI or I2C, not some one-wire-protocol. Suggestions, BMP180 (temp, RHum), TSL2561 (light).

Have fun!

edit: if you are doing it on the Arduino, you can start off with the arduino spi/i2c libs, and later on if you wish, fire up the AVR datasheet (or whatever cpu is on your arduino) and implement i2c/spi yourself by changing registers etc on the cpu.

Re: Effective C: An Introduction to Professional C Programming

#100
post #88

Earlier quoted context omitted.

If you are looking for a full course this one isn't bad: Embedded Systems Shape the World [0] it does hew pretty close to platform specifics (Windows/Keil/TI Launchpad) which can be good for specifics and not good for holistic understanding. I have had a lot of fun following Ben Eater's[1] projects, which aren't always embedded-specific (sometimes they're TTL, sometimes Arduino) but are excellent for understanding co…

From a C-veteran perspective, what do you think about type safe (e.g. dependent types such in ATS, or F*/KreMLin, or other DSLs) languages that compile to C, or a subset of C? How could one get the safety promises that are observed in Rust in C? Thanks!

I'm not the OP you're asking, I'll provide my own answer to the latter question though.

C is a language that doesn't come with many guarantees. I personally like to think of C as a 'higher-level assembler', targeting a virtual machine. I've been led to believe that this figurative description of the language was more common in the past than it is today. I find it a helpful description since it offers an explanation for many of C's design choices. Such as it's weak types and use of pointers. If I'm correct it's also an accurate description of the language's original aims in system development.

Also, Rust isn't the only systems programming language with a focus on safety. Ada has been around for some time now and is a much more mature language and arguably more suited for the job. It has a demonstrable track record of successful use in safety-critical software. Rust is definitely more 'C-like' than Ada, which might make it preferable to many.

Post reply on HN