Embedded Systems Take Off

As Nobel-laureate Murray Gell-Mann described it at the 2002 Embedded Systems Conference in San Francisco, embedded systems is about putting a computer in a bed so the bed automatically moves to best enhance the activities that any couple on the bed may be engaging in (to put it tactfully). The concept extends to more than beds of course, but properly done, it’s clear why this technology will be a winner.

Judging from the products presented at the 2002 Embedded Systems Conference in San Francisco, embedded systems are ready for a number of advertising & marketing applications for the small to mid-sized business, ranging from desktop kiosks to Internet connected coffee makers.

The history of embedded systems goes back at least to the sixties, but the expense and limitations of the early systems limited their use. Embedded systems really took off in 1992, when the PC/104 Consortium was founded by Ampro, RTD, and other manufacturers. The group established a format for Intel microprocessors based on a motherboard approximately four inches square, and just under an inch high. The boards were stackable, allowing a very powerful computer to be assembled in a box approximately four inches square, or even less.

The PC/104 was initially targeted at military and medical markets, where it became widely used and respected. When the processor power increased enough to handle multimedia applications, PC/104-based kiosks became possible, and eventually common.

Today, there are estimated to be well over 100 different companies making PC/104 products. There are PC/104 cards to add ethernet, FireWire, hard drives, RAM drives, video cards, audio cards, general I/O, flash cards, modems, GPS, cellular telephone, wireless Internet, and more, to the PC/104 motherboard of your choice. Some off-the-shelf PC/104 cases can handle up to 13 or more cards, so your budget is your only constraint.

Links: http://www.ad-mkt-review.com/public_html/air/ai200205.html

The ‘C’ test. Part – XVI

Obscure syntax


16. ‘C’ allows some appalling constructs. Is this construct legal, and if so what does this code do?

int a = 5, b = 7, c;
c = a+++b;

This question is intended to be a lighthearted end to the quiz, as, believe it or not, this is perfectly legal syntax. The question is how does the compiler treat it? Those poor compiler writers actually debated this issue, and came up with the “maximum munch” rule, which stipulates that the compiler should bite off as big (and legal) a chunk as it can. Hence, this code is treated as:

c = a++ + b;

Thus, after this code is executed, a = 6, b = 7, and c = 12.

If you knew the answer, or guessed correctly, well done. If you didn’t know the answer then I wouldn’t consider this to be a problem. I find the greatest benefit of this question is that it is good for stimulating questions on coding styles, the value of code reviews, and the benefits of using lint.

Well folks, there you have it. That was my version of the C test. I hope you had as much fun taking it as I had writing it. If you think the test is a good test, then by all means use it in your recruitment. Who knows, I may get lucky in a year or two and end up being on the receiving end of my own work.

 Links:

for “The ‘C’ test. Part – I”  to  “The ‘C’ test. Part – XVI”

http://www.embedded.com/2000/0005/0005feat2.htm

http://www.embedded.com/98/9811/9811fe3.htm 

The ‘C’ test. Part – XV

Typedef
15. Typedef is frequently used in C to declare synonyms for pre-existing data types. It is also possible to use the preprocessor to do something similar. For instance, consider the following code fragment:

#define dPS struct s *
typedef struct s * tPS;

The intent in both cases is to define dPS and tPS to be pointers to structure s. Which method, if any, is preferred and why?

This is a very subtle question, and anyone who gets it right (for the right reason) is to be congratulated or condemned (“get a life” springs to mind). The answer is the typedef is preferred. Consider the declarations:

dPS p1,p2;
tPS p3,p4;

The first expands to:

struct s * p1, p2;

which defines p1 to be a pointer to the structure and p2 to be an actual structure, which is probably not what you wanted. The second example correctly defines p3 and p4 to be pointers

The ‘C’ test. Part – XIV

Dynamic memory allocation

14. Although not as common as in non-embedded computers, embedded systems do still dynamically allocate memory from the heap. What are the problems with dynamic memory allocation in embedded systems?

Here, I expect the user to mention memory fragmentation, problems with garbage collection, variable execution time, and so on. This topic has been covered extensively in ESP , mainly by P.J. Plauger. His explanations are far more insightful than anything I could offer here, so go and read those back issues! Having lulled the candidate into a sense of false security, I then offer up this tidbit:


What does the following code fragment output and why?

char *ptr;
if ((ptr = (char *)malloc(0)) ==NULL)

puts(“Got a null pointer”);
else
puts(“Got a valid pointer”);

This is a fun question. I stumbled across this only recently when a colleague of mine inadvertently passed a value of 0 to malloc and got back a valid pointer! That is, the above code will output “Got a valid pointer.” I use this to start a discussion on whether the interviewee thinks this is the correct thing for the library routine to do. Getting the right answer here is not nearly as important as the way you approach the problem and the rationale for your decision.

…to be continued 

The ‘C’ test. Part – XIII

13. Comment on the following code fragment.

unsigned int zero = 0;
unsigned int compzero = 0xFFFF;
/*1’s complement of zero */

On machines where an int is not 16 bits, this will be incorrect. It should be coded:

unsigned int compzero = ~0;

This question really gets to whether the candidate understands the importance of word length on a computer. In my experience, good embedded programmers are critically aware of the underlying hardware and its limitations, whereas computer programmers tend to dismiss the hardware as a necessary annoyance.

By this stage, candidates are either completely demoralized-or they’re on a roll and having a good time. If it’s obvious that the candidate isn’t very good, then the test is terminated at this point. However, if the candidate is doing well, then I throw in these supplemental questions. These questions are hard, and I expect that only the very best candidates will do well on them. In posing these questions, I’m looking more at the way the candidate tackles the problems, rather than the answers.

…to be continued