Over the years have I made a programming journey from C in 1990 to Pascal, C++ with I programmed commercially, java VHDL, C# and now I'm taking a look on F#.

In the spring I will go back to study embedded programming in C in a university course so before I do that I will refresh my knowledge in C.
I don't remember much of the C that I learnt and I think I am thankful for that for probably learned some bad habits back then.

I have some questions to get me on the way.
To clarify: I am thankful for tips that have been given regarding embedded programming but now I am more interested in relearning C in general. Sorry if my question was unclear,

  1. Compiler, Debugger, IDE? As a microslave I was thinking about 2010 C++ Express, any alternatives?
  2. Where do you find good libraries with code for C. I'm thinking something similar to Boost, POCO in C++
  3. Source for procedural programming patterns and best practices. Where can you find good code learn from?

Thanks in advance

  1. GCC, GDB, Eclipse can be a decent multi-platform alternative.
  2. From my experience, especially in embedded environment, you more often have to build your own specific library, than use a third party library that may be too big, or not enough. There is always small code snippets for FTP connection, or bigger libraries for SQL support, but I find it really project-specific so far, not widespread like boost. I'd like to hear from others as well for this specific point.
  3. K&R, C interfaces and implementations , Expert C Programming are good C readings.
|improve this answer|||||
  • where do you find code snippets? specific sites? – user1041 Nov 24 '10 at 8:11
  • @Gorgen CCAN (ccan.ozlabs.org) is a great place to grab all kinds of gems. – Tim Post Nov 24 '10 at 8:40

There is a very good chance for embedded C programming that you will end up with using the GNU C compiler to target the destination platform, so you might as well learn to use gcc along with gdb to debug (perhaps even using Emacs as both a C IDE which is pretty good, and as the gdb frontend).

For this you essentially just need any modern Linux distribution which contain all of the above - usually as optional packages just requiring a single command to install.

This looks like a good C tutorial : http://www.faqs.org/docs/learnc/

You will naturally need the K&R manual. Use ANSI C if you can.

|improve this answer|||||
  • +1, If on windows you can run gcc native (MinGW is probably easiest), in cygwin or SUA – Jeremy Nov 23 '10 at 20:40
  • @Jeremy, I would rather suggest running Linux in a free virtual machine (vmware player, virtualbox etc), as you have a single homogeneous environment. There are simply too many rough edges for Windows-hosted scenarios for a learner (even though it is a different matter for an experienced developer). – user1249 Nov 23 '10 at 20:47
  • Yes you are probably right. – Jeremy Nov 24 '10 at 0:33

I can't say enough good things about Valgrind for memory error detection, spotting leaks, profiling (massif), not mentioning helgrind / cachegrind. Used in combination with a debugger such as GDB, many problems become shallow and trivial to correct.

Unfortunately, Valgrind isn't yet 'officially' ported to all popular embedded architectures, but it isn't far away.

The other thing I recommend doing is taking advantage of the fact that GCC is self hosting, it can compile itself for an array of architectures. Being able to manage cross compilation is very important - the system that actually compiles your code is quite often not the system that will actually run it.

Finally, get as intimate as you can with how malloc() is implemented. You might want to implement a garbage collector, use a static pool in lieu of asking the kernel for each block or do your own profiling / debugging. This coincides with the reference you made to alternative C library implementations.

|improve this answer|||||

It depends on whether you will be working with 8/16 bit microcontrollers (without an OS) or 32-bit microprocessors using (for example) embedded Linux. As others have mentioned, with the latter you will probably be using a gcc toolchain of some type.

However if you are going to be programming smaller devices, then the IDE and compilers are usually designed specifically for a family of MCUs. Chip makers often sell (or give away) IDEs and compilers for their products (e.g. Microchip and Freescale). (The free versions may be limited either by object size or optimization features). There are some companies (like Keil and IAR) that make compilers for several different families.

|improve this answer|||||
  • what kind of services can I expect from the embedded os? I can imagine TCP/IP stack. maybe some kind of file system. – user1041 Nov 24 '10 at 8:22
  • On one of my current projects, after I found an RTOS (real-time OS) for the chip (8051 variant) I am using, I needed to find a FAT-16 file system (for an SD card) elsewhere. TCP/IP, Bluetooth and Zigbee stacks are typically packaged separately also. The RTOS has task creation/switching, signals, and messages. – tcrosley Nov 24 '10 at 14:51

I use Komodo and compile and debug using Xcode. Xcode uses the GDB debugger, but IMHO it is WAY easier to use.

If you use cmake, you can output xcode project files and compile under bsd and linux.

|improve this answer|||||

In terms of an IDE to use, I'm a big fan of using Microsoft's IDE products for EDITING files, but using Makefiles and gcc to compile.

I know you've indicated you're interested in non-embedded specific stuff, but your library and compiler questions are still influenced by what you're going to be doing.

As such, I'd definately be thinking against linking against uClibc for embedded programming: http://www.uclibc.org/

If you're not targeting x86, you'll want to think about your cross-compile environment - I've been looking at some options for this recently, and it looks like scratchbox might be the best way to go, but YMMV: http://www.scratchbox.org/

Besides that, you shouldn't really have to 're-learn' C, rather just look at changing up your toolchain for the specific task at hand.

Hope this helps.

|improve this answer|||||
  • The reason why I said I wanted to re-learn C is that I didn't programmed ideomaticly, it was my first programming course on the university and my first programming exprience. This time I don't want to learn bad habits that I have to unlearn again. – user1041 Nov 24 '10 at 8:36
  • Fair enough. I guess if you want to get back into the C-isms of the language then some good exercises might be to write your own implementations of string handling functions using only core language features - writing your own linked list structures and functions and whatnot. – heretik Nov 24 '10 at 14:07
  • I am speechless, well, and without templates... my own linked list. I have to cast void pointers for the payload of each node I suppose.... – user1041 Nov 24 '10 at 14:30