一、預處理器(Preprocessor)html
二、如何定義宏linux
三、預處理器標識#error的目的是什麼?ios
四、死循環(Infinite loops)程序員
五、數據聲明(Data declarations)面試
六、關鍵字static的做用是什麼?spring
七、關鍵字const有什麼含意?express
八、Volatile的使用編程
九、位操做(Bit manipulation)數組
十、訪問固定的內存位置(Accessing fixed memory locations)緩存
十一、中斷(Interrupts)
十二、符號擴展的代碼例子(Code examples)
1三、處理器字長致使的數據擴展問題
1四、動態內存分配(Dynamic memory allocation)
1五、用Typedef構造複合類型
1六、晦澀的語法及代碼風格
C語言測試是招聘嵌入式系統程序員過程當中必須並且有效的方法。這些年,我既參加也組織了許多這種測試,在這過程當中我意識到這些測試能爲面試者和被面試者提供許多有用信息,此外,撇開面試的壓力不談,這種測試也是至關有趣的。
從被面試者的角度來說,你能瞭解許多關於出題者或監考者的狀況。這個測試只是出題者爲顯示其對ANSI標準細節的知識而不是技術技巧而設計嗎?這是個愚蠢的問題嗎?如要你答出某個字符的ASCII值。這些問題着重考察你的系統調用和內存分配策略方面的能力嗎?這標誌着出題者也許花時間在微機上而不是在嵌入式系統上。若是上述任何問題的答案是"是"的話,那麼我知道我得認真考慮我是否應該去作這份工做。
從面試者的角度來說,一個測試也許能從多方面揭示應試者的素質:最基本的,你能瞭解應試者C語言的水平。無論怎麼樣,看一下這人如何回答他不會的問題也是滿有趣。應試者是以好的直覺作出明智的選擇,仍是隻是瞎蒙呢?當應試者在某個問題上卡住時是找藉口呢,仍是表現出對問題的真正的好奇心,把這當作學習的機會呢?我發現這些信息與他們的測試成績同樣有用。
有了這些想法,我決定出一些真正針對嵌入式系統的考題,但願這些使人頭痛的考題能給正在找工做的人一點幫助。這些問題都是我這些年實際碰到的。其中有些題很難,但它們應該都能給你一點啓迪。
這個測試適於不一樣水平的應試者,大多數初級水平的應試者的成績會不好,經驗豐富的程序員應該有很好的成績。爲了讓你能本身決定某些問題的偏好,每一個問題沒有分配分數,若是選擇這些考題爲你所用,請自行按你的意思分配分數。
用預處理指令#define 聲明一個常數,用以代表1年中有多少秒(忽略閏年問題)
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL(大小寫都行,常量後面能夠加此標誌,宏的命名風格要大寫,多個之間用下劃線)
我在這想看到幾件事情:
1) #define 語法的基本知識(例如:不能以分號結束,括號的使用(表達式、參數等要括起來),等等)
2)懂得預處理器將爲你計算常數表達式的值(難道不是替換麼,先算再替?會將常數合併),所以,直接寫出你是如何計算一年中有多少秒而不是計算出實際的值,是更清晰而沒有代價的。
3) 意識到這個表達式將使一個16位機的整型數溢出-所以要用到長整型符號L,告訴編譯器這個常數是的長整型數。
4) 若是你在你的表達式中用到UL(表示無符號長整型),那麼你有了一個好的起點。記住,第一印象很重要。
寫一個"標準"宏MIN ,這個宏輸入兩個參數並返回較小的一個。
考點:(表達式、參數等要括起來)
#define MIN(A,B) ((A) <= (B) ? (A) : (B))
這個測試是爲下面的目的而設的:
1) 標識#define在宏中應用的基本知識。這是很重要的。由於在嵌入(inline)操做符變爲標準C的一部分以前,宏是方便產生嵌入代碼的惟一方法,對於嵌入式系統來講,爲了能達到要求的性能(固然主要是實時性哦,犧牲代碼空間換取時間效率),嵌入代碼常常是必須的方法。
2)三重條件操做符的知識。這個操做符存在C語言中的緣由是它使得編譯器能產生比if-then-else(存在條件轉移會中斷指令流水線)更優化的代碼,瞭解這個用法是很重要的。
3) 懂得在宏中當心地把參數用括號括起來
4) 我也用這個問題開始討論宏的反作用,例如:當你寫下面的代碼時會發生什麼事?
least = MIN(*p++, b);
此處考點:inline函數和宏的區別
宏只是將參數徹底替換,即MIN(*p++, b)進行宏展開後爲((*p++) <= (b) ? (*p++) : (b)),若是(*p++) <= (b)成立,則表達式的值爲(*p++),但因爲在(*p++)<= (b)判斷過程當中改變了p的值,使得此時的? (*p++)非(*p++)<= (b)中的值了,違背了?號表達式的原意。
可是內聯inline函數將進行參數檢查,求出參數的值後再將此值帶入函數中,所以((A) <= (B) ? (A) : (B))中的A是一致的。
第一部分:宏
爲何要使用宏呢?
由於函數的調用必需要將程序執行的順序轉移到函數所存放在內存中的某個地址,將函數的程序內容執行完後,再返回到轉去執行該函數前的地方。這種轉移操做要求在轉去執行前要保存現場並記憶執行的地址,轉回後要恢復現場,並按原來保存地址繼續執行。所以,函數調用要有必定的時間和空間方面的開銷,因而將影響其效率。
而宏只是在預處理的地方把代碼展開,不須要額外的空間和時間方面的開銷,因此調用一個宏比調用一個函數更有效率。
可是宏也有不少的不盡人意的地方。
1、宏不能訪問對象的私有成員。
2、宏的定義很容易產生二意性。
3、宏定義的常量在代碼區,不少調試器不可以對其調試
咱們舉個例子:
#define square(x) (x*x)
避免這些錯誤的方法,一是給宏的參數都加上括號。
#define square(x) ((x)*(x))
第二部分:內聯函數
從上面的闡述,能夠看到宏有一些難以免的問題,怎麼解決呢?
內聯函數是代碼被插入到調用者代碼處的函數。如同 #define 宏,內聯函數經過避免被調用的開銷來提升執行效率,尤爲是它可以經過調用(「過程化集成」)被編譯器優化。
內聯函數和宏很相似,而本質區別在於,宏是由預處理器對宏進行替代,而內聯函數是經過編譯器控制來實現的。並且內聯函數是真正的函數,只是在須要用到的時候,內聯函數像宏同樣的展開,因此取消了函數的參數壓棧,減小了調用的開銷。你能夠象調用函數同樣來調用內聯函數,而沒必要擔憂會產生於處理宏的一些問題。
聲明內聯函數看上去和普通函數很是類似:
void f(int i, char c);
當你定義一個內聯函數時,在函數定義前加上 inline 關鍵字,而且將定義放入頭文件:
inline void f(int i, char c)
{
// ...
}
內聯函數必須是和函數體的定義申明在一塊兒,纔有效。
像這樣的申明inline function(int i)是沒有效果的,編譯器只是把函數做爲普通的函數申明,咱們必須定義函數體。
inline int function(int i) {return i*i;}
這樣咱們纔算定義了一個內聯函數。咱們能夠把它做爲通常的函數同樣調用。可是執行速度確比通常函數的執行速度要快。
固然,內聯函數也有必定的侷限性。就是函數中的執行代碼不能太多了,若是,內聯函數的函數體過大,通常的編譯器會放棄內聯方式,而採用普通的方式調用函數。這樣,內聯函數就和普通函數執行效率同樣了。
有上面的二者的特性,咱們能夠用內聯函數徹底取代預處理宏。
若是你不知道答案,請看參考文獻1。這問題對區分一個正常的夥計和一個書呆子是頗有用的。只有書呆子纔會讀C語言課本的附錄去找出象這種問題的答案。固然若是你不是在找一個書呆子,那麼應試者最好但願本身不要知道答案。
嵌入式系統中常常要用到無限循環,你怎麼樣用C編寫死循環呢? 這個問題用幾個解決方案。
我首選的方案是:
while(1)
{
}
一些程序員更喜歡以下方案:
for(;;) (此處的判斷效率要低的多,在彙編代碼中看看???)
{
}
這個實現方式讓我爲難,由於這個語法沒有確切表達到底怎麼回事。若是一個應試者給出這個做爲方案,我將用這個做爲一個機會去探究他們這樣作的基本原理。若是他們的基本答案是:"我被教着這樣作,但從沒有想到過爲何。"這會給我留下一個壞印象。 (不少時候面試官關注你思考問題的方式,是否留意某些東西善於思考,可能並無對錯,只是偏好而已,好比memset和memcopy以及strcpy都能拷貝字符串,到底有什麼區別呢?看你是否善於比較是否關注細節)
第三個方案是用 goto (goto語句在C中是應該儘可能避免的,只在處理錯誤代碼時用)
Loop:
...
goto Loop;
應試者如給出上面的方案,這說明或者他是一個彙編語言程序員(這也許是好事)或者他是一個想進入新領域的BASIC/FORTRAN程序員。
用變量a給出下面的定義
a) 一個整型數(An integer)
b)一個指向整型數的指針( A pointer to an integer)
c)一個指向指針的的指針,它指向的指針是指向一個整型數( A pointer to a pointer to an integers)
d)一個有10個整型數的數組( An array of 10 integers)
e) 一個有10個指針的數組,該指針是指向一個整型數的。(An array of 10 pointers to integers)
f) 一個指向有10個整型數數組的指針( A pointer to an array of 10 integers)
g) 一個指向函數的指針,該函數有一個整型參數並返回一個整型數(A pointer to a function that takes an integer as an argument and returns an integer)
h) 一個有10個指針的數組,該指針指向一個函數,該函數有一個整型參數並返回一個整型數( An array of ten pointers to functions that take an integer argument and return an integer )
答案是:
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer // 不是(int x),不須要具體的參數
h) int (*a[10])(int)(能夠從e、g類比獲得); // An array of 10 pointers to functions that take an integer argument and return an integer
人們常常聲稱這裏有幾個問題是那種要翻一下書才能回答的問題,我贊成這種說法。當我寫這篇文章時,爲了肯定語法的正確性,個人確查了一下書。可是當我被面試的時候,我指望被問到這個問題(或者相近的問題)。由於在被面試的這段時間裏,我肯定我知道這個問題的答案。應試者若是不知道全部的答案(或至少大部分答案),那麼也就沒有爲此次面試作準備,若是該面試者沒有爲此次面試作準備,那麼他又能爲何作準備呢?
這個簡單的問題不多有人能回答徹底。在C語言中,關鍵字static有三個明顯的做用:
1)在函數體內,一個被聲明爲靜態的變量在這一函數被調用過程當中維持其值不變(該變量存放在靜態變量區)。
2) 在模塊內(但在函數體外),一個被聲明爲靜態的變量能夠被模塊內所用函數訪問,但不能被模塊外其它函數訪問。它是一個本地的全局變量。
3) 在模塊內,一個被聲明爲靜態的函數只可被這一模塊內的其它函數調用。那就是,這個函數被限制在聲明它的模塊的本地範圍內使用。
大多數應試者能正確回答第一部分,一部分能正確回答第二部分,可是不多的人能懂得第三部分。這是一個應試者的嚴重的缺點,由於他顯然不懂得本地化數據和代碼範圍的好處和重要性。
考點:在嵌入式系統中,要時刻懂得移植的重要性,程序多是不少程序員共同協做同時完成,在定義變量及函數的過程,可能會重名,這給系統的集成帶來麻煩,所以保證不衝突的辦法是顯示的表示此變量或者函數是本地的,static便可。
在Linux的模塊編程中,這一條很明顯,全部的函數和全局變量都要用static關鍵字聲明,將其做用域限制在本模塊內部,與其餘模塊共享的函數或者變量要EXPORT到內核中。
static關鍵字至少有下列n個做用:
(1)設置變量的存儲域,函數體內static變量的做用範圍爲該函數體,不一樣於auto變量,該變量的內存只被分配一次,所以其值在下次調用時仍維持上次的值;
(2)限制變量的做用域,在模塊內的static全局變量能夠被模塊內所用函數訪問,但不能被模塊外其它函數訪問;
(3)限制函數的做用域,在模塊內的static函數只可被這一模塊內的其它函數調用,這個函數的使用範圍被限制在聲明它的模塊內;
(4)在類中的static成員變量意味着它爲該類的全部實例所共享,也就是說當某個類的實例修改了該靜態成員變量,其修改值爲該類的其它全部實例所見;
(5)在類中的static成員函數屬於整個類所擁有,這個函數不接收this指針,於是只能訪問類的static成員變量。
我只要一聽到被面試者說:"const意味着常數"(不是常數,能夠是變量,只是你不能修改它),我就知道我正在和一個業餘者打交道。去年Dan Saks已經在他的文章裏徹底歸納了const的全部用法,所以ESP(譯者:Embedded Systems Programming)的每一位讀者應該很是熟悉const能作什麼和不能作什麼.若是你從沒有讀到那篇文章,只要能說出const意味着"只讀"就能夠了。儘管這個答案不是徹底的答案,但我接受它做爲一個正確的答案。(若是你想知道更詳細的答案,仔細讀一下Saks的文章吧。)
若是應試者能正確回答這個問題,我將問他一個附加的問題:下面的聲明都是什麼意思?
Const只是一個修飾符,無論怎麼樣a仍然是一個int型的變量
const int a;
int const a;
const int *a;
int * const a;
int const * a const;
本質:const在誰後面誰就不可修改,const在最前面則將其後移一位便可,兩者等效
前兩個的做用是同樣,a是一個常整型數。第三個意味着a是一個指向常整型數的指針(也就是,指向的整型數是不可修改的,但指針能夠,此最多見於函數的參數,當你只引用傳進來指針所指向的值時應該加上const修飾符,程序中修改編譯就不經過,能夠減小程序的bug)。
第四個意思a是一個指向整型數的常指針(也就是說,指針指向的整型數是能夠修改的,但指針是不可修改的)。最後一個意味着a是一個指向常整型數的常指針(也就是說,指針指向的整型數是不可修改的,同時指針也是不可修改的)。
若是應試者能正確回答這些問題,那麼他就給我留下了一個好印象。順帶提一句,也許你可能會問,即便不用關鍵字 ,也仍是能很容易寫出功能正確的程序,那麼我爲何還要如此看重關鍵字const呢?我也以下的幾下理由:
1) 關鍵字const的做用是爲給讀你代碼的人傳達很是有用的信息,實際上,聲明一個參數爲常量是爲了告訴了用戶這個參數的應用目的。若是你曾花不少時間清理其它人留下的垃圾,你就會很快學會感謝這點多餘的信息。(固然,懂得用const的程序員不多會留下的垃圾讓別人來清理的。)
2) 經過給優化器一些附加的信息,使用關鍵字const也許能產生更緊湊的代碼。
3) 合理地使用關鍵字const可使編譯器很天然地保護那些不但願被改變的參數,防止其被無心的代碼修改。簡而言之,這樣能夠減小bug的出現。
const關鍵字至少有下列n個做用:
(1)欲阻止一個變量被改變,可使用const關鍵字。在定義該const變量時,一般須要對它進行初始化,由於之後就沒有機會再去改變它了;
(2)對指針來講,能夠指定指針自己爲const,也能夠指定指針所指的數據爲const,或兩者同時指定爲const;
(3)在一個函數聲明中,const能夠修飾形參,代表它是一個輸入參數,在函數內部不能改變其值;
(4)對於類的成員函數,若指定其爲const類型,則代表其是一個常函數,不能修改類的成員變量;
(5)對於類的成員函數,有時候必須指定其返回值爲const類型,以使得其返回值不爲「左值」。例如:
const classA operator*(const classA& a1,const classA& a2);
operator*的返回結果必須是一個const對象。若是不是,這樣的變態代碼也不會編譯出錯:
classA a, b, c;
(a * b) = c; // 對a*b的結果賦值
操做(a * b) = c顯然不符合編程者的初衷,也沒有任何意義。
關鍵字volatile有什麼含意?並給出三個不一樣的例子。
一個定義爲volatile的變量是說這變量可能會被意想不到地改變,這樣,編譯器就不會去假設這個變量的值了。精確地說就是,優化器在用到這個變量時必須每次都當心地從新讀取這個變量的值,而不是使用保存在寄存器裏的備份(因爲訪問寄存器的速度要快過RAM,因此編譯器通常都會做減小存取外部RAM的優化)。下面是volatile變量的幾個例子:
1) 並行設備的硬件寄存器(如:狀態寄存器,一般在頭文件中將硬件寄存器地址define爲某個意義明確的表達式)
2) 一箇中斷服務子程序中會訪問到的非自動變量(Non-automatic variables,即static變量) ;在中斷服務程序中修改的供其餘程序檢測用的變量須要加volatile聲明;不然編譯器可能對變量更新一次後每次都使用緩存值再也不當即更新;
3) 多線程應用中被幾個任務共享的變量(可能被多個線程隨時修改)
回答不出這個問題的人是不會被僱傭的。我認爲這是區分C程序員和嵌入式系統程序員的最基本的問題。搞嵌入式的傢伙們常常同硬件、中斷、RTOS等等打交道,全部這些都要求用到volatile變量。不懂得volatile的內容將會帶來災難。假設被面試者正確地回答了這是問題(嗯,懷疑是否會是這樣),我將稍微深究一下,看一下這傢伙是否是直正懂得volatile徹底的重要性。
1)一個參數既能夠是const還能夠是volatile嗎?解釋爲何。
2); 一個指針能夠是volatile 嗎?解釋爲何。
3); 下面的函數有什麼錯誤:
int square(volatile int *ptr)
{
return *ptr * *ptr;
}
下面是答案:
1)是的。一個例子是隻讀的狀態寄存器。它是volatile由於它可能被意想不到地改變。它是const由於程序不該該試圖去修改它。
2); 是的。儘管這並不很常見。一個例子是當一箇中斷服務子程序修改一個指向一個buffer的指針時。
3) 這段代碼有點變態。這段代碼的目的是用來返回指針*ptr指向值的平方,可是,因爲*ptr指向一個volatile型參數,編譯器將產生相似下面的代碼:
int square(volatile int *ptr)
{
int a,b;
a = *ptr;
b = *ptr;
return a * b;
}
因爲*ptr的值可能被意想不到地該變,所以a和b多是不一樣的。結果,這段代碼可能返不是你所指望的平方值!正確的代碼以下:
long square(volatile int *ptr)
{
int a;
a = *ptr;
return a * a;
}
關於volatile關鍵字在中斷函數中的影響實例
串口發送數據,中斷中對其檢測,當中斷產生後,置接收標誌,主循環中檢測此主標誌,未用valotile修飾時,編譯結果以下:
[0xe59f41bc] ldr r4,0x30203378 ; = #0x302096f0
0x302031b8 [0xe5d40000] ldrb r0,[r4,#0]
while(!uart1_rxFlag); //uart1_rxFlag爲全局變量,在串口接收中斷中置1
0x302031bc [0xe3500000] cmp r0,#0
0x302031c0 [0x0afffffd] beq 0x302031bc; (Can_Int_Test + 0x17c)
即編譯器對其進行了優化,讀取一次uart1_rxFlag的值以後,將其存放在寄存器r0中,比較後,條件不知足,繼續等待,但未從新取存儲器中uart1_rxFlag的值,此時即便中斷服務函數中修改了uart1_rxFlag的值,比較處仍然不能發現,就出現了不管如何程序就停在此處的問題。
// 加了volatile關鍵字後,編譯的結果
302031b4 ldr r4,0x30203378 ; = #0x302096f0
while(uart1_rxFlag == 0);
302031b8 [0xe5d40000] ldrb r0,[r4,#0]
302031bc [0xe3500000] cmp r0,#0
302031c0 [0x0afffffc] beq 0x302031b8 ; (Can_Int_Test + 0x288)
添加了關鍵字後,比較不等,跳轉到從新取存儲器中的uart1_rxFlag,所以任什麼時候候uart1_rxFlag的值都是最新的。
必定程度的優化,去掉了讀取uart1_rxFlag地址的語句。
定義一個易失性變量,編譯器有一種技術叫數據流分析,分析程序中的變量在哪裏被賦值、在哪裏使用、在哪裏失效,分析結果能夠用於常量合併,常量傳播等優化。當編譯器檢查到代碼沒有修改字段的值,就有可能在你訪問字段時提供上次訪問的緩存值,這可以提升程序的效率,但有時這些優化會帶來問題,不是咱們程序所須要的,特色是對硬件寄存器操做的程序,這時能夠用volatile關鍵字禁止作這些優化。
多任務環境下各任務間共享的標誌應該加voatile關鍵字:在多線程訪問某字段時,代碼但願這些訪問可以操做(讀取)到字段的最新值,同時寫到變量的操做能當即更新;對字段加上volatile關鍵字,那麼對該字段的任何請求(讀/寫)都會馬上獲得執行。
嵌入式系統老是要用戶對變量或寄存器進行位操做。給定一個整型變量a,寫兩段代碼,第一個設置a的bit 3,第二個清除a 的bit 3。在以上兩個操做中,要保持其它位不變。 對這個問題有三種基本的反應
1)不知道如何下手。該被面者從沒作過任何嵌入式系統的工做。
2) 用bit fields。Bit fields是被扔到C語言死角的東西,它保證你的代碼在不一樣編譯器之間是不可移植的,同時也保證了的你的代碼是不可重用的。
3) 用 #defines 和 bit masks 操做。這是一個有極高可移植性的方法,是應該被用到的方法。最佳的解決方案以下:
#define BIT3 (0x1 << 3) (採用宏將數字定義爲有意義的BIT3,明確,不易出錯,改起來方便)
static int a;
void set_bit3(void)
{
a |= BIT3;
}
void clear_bit3(void)
{
a &= ~BIT3;
}
一些人喜歡爲設置和清除值而定義一個掩碼(待操做位全1,其他位全0的數,對於某個意義靠多位同時表示的最好帶上掩碼,隔離其餘位的影響)同時定義一些說明常數,這也是能夠接受的。我但願看到幾個要點:說明常數、|=和&=~操做,先取反再&是對某位清0的最好操做。
考點:
在嵌入式系統中,時刻要關注移植性,具體的程序中不要出現具體的數字,這些數字都應該define成某個有意義的符號,可讀性可移植性都很強,好比
#define BIT(x) (0x1 << (x))
X做爲參數能夠很方便的對任意位進行操做,意義明確,更改替換方便
嵌入式系統常常具備要求程序員去訪問某特定的內存位置的特色。
在某工程中,要求設置一絕對地址爲0x67a9的整型變量的值爲0xaa66。編譯器是一個純粹的ANSI編譯器。寫代碼去完成這一任務。這一問題測試你是否知道爲了訪問一絕對地址把一個整型數強制轉換(typecast)爲一指針是合法的。這一問題的實現方式隨着我的風格不一樣而不一樣。典型的相似代碼以下:
int *ptr;
ptr = (int *)0x67a9;
*ptr = 0xaa55;
A more obscure approach is: ( 一個較晦澀的方法是):
*(int * const)(0x67a9) = 0xaa55;
即便你的品味更接近第二種方案,但我建議你在面試時使用第一種方案。
在嵌入式系統中,對於大量此類型數據如硬件寄存器應該採用以下方式
typedef volatile unsigned int HARD_REG;
#define REG_NAME (*(HARD_REG *)ADDR)
即將ADDR強制轉換爲一個指向HARD_REG類型數據的指針,*HARD_REG爲volatile的無符號整型數
中斷是嵌入式系統中重要的組成部分,這致使了不少編譯開發商提供一種擴展-讓標準C支持中斷。其表明事實是,產生了一個新的關鍵字 __interrupt(51即如此)。下面的代碼就使用了__interrupt關鍵字去定義了一箇中斷服務子程序(ISR),請評論一下這段代碼的。
__interrupt double compute_area (double radius)
{
double area = PI * radius * radius;
printf("/nArea = %f", area);
return area;
}
這個函數有太多的錯誤了,以致讓人不知從何提及了(前提是非操做系統下的中斷服務函數):
1)ISR 不能返回一個值(都應該爲void類型)。若是你不懂這個,那麼你不會被僱用的。
2)ISR 不能傳遞參數。若是你沒有看到這一點,你被僱用的機會等同第一項。
3)在許多的處理器/編譯器中,浮點通常都是不可重入的。有些處理器/編譯器須要讓額外的寄存器入棧,有些處理器/編譯器就是不容許在ISR中作浮點運算。此外,ISR應該是短而有效率的,在ISR中作浮點運算是不明智的。
///////////////////////////////
另外中斷服務程序是運行在內核態的(linux),內核一般是不支持浮點運算的。
http://access911.net/n/doc1.asp?mode=a&aid=4750647
內核中的printk和標準庫的printf不同,前者由於由內核直接實現,不能支持浮點。
在<linux內核設計與實現>的第一章中內核開發的特色一小節裏就有比較了內核開發與應用開發的差別。其中一點就是內核編程時浮點數的問題,書中有一句話是:內核編程時浮點數很難使用
由於沒有浮點單元,內核要支持浮點必須把內核以soft-float 方式從新編譯,其鏈接全部的庫也都要用soft-float 方式編譯.
不然另一種方式使用整數定義浮點類型加浮點預算庫完成你的工做,
http://topic.csdn.net/u/20070417/16/a4b56569-228c-4b70-b5ab-30ee61c99a3d.html
若是你的內核裏編譯進了浮點支持,那麼是能夠的。要不內核或是模塊不能用float或是double內型的變量或函數
在配置內核的時候把浮點模擬器選上,應該是能夠支持的,可是速度很是慢。
我曾經遇到過,硬件明明支持浮點運算的FPU,可是編譯內核的時候選上了浮點模擬器,結果全部的應用程序的浮點運算速度都很是慢。因此我懷疑要支持浮點只要編譯內核的時候選上,對於應用程序不須要怎麼關心。
///////////////////////////////
4) 與第三點一脈相承,printf()常常有重入和性能上的問題。若是你丟掉了第三和第四點,我不會太爲難你的。不用說,若是你能獲得後兩點,那麼你的被僱用前景愈來愈光明瞭。
下面的代碼輸出是什麼,爲何?
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") : puts("<= 6");
}
Vc6.0測試狀況
void main(void)
{
unsigned int a = 6;
int b = -20;
printf("unsigned int a + int b = %x/n", (a + b));
}
/*unsigned int a + int b = fffffff2*/
這個問題測試你是否懂得C語言中的整數自動轉換原則,我發現有些開發者懂得極少這些東西。無論如何,這無符號整型問題的答案是輸出是 ">6"。緣由是當表達式中存在有符號類型和無符號類型時全部的操做數都自動轉換爲無符號類型。所以-20變成了一個很是大的正整數,因此該表達式計算出的結果大於6。這一點對於頻繁用到無符號數據類型的嵌入式系統(硬件寄存器的值所有是無符號的)來講是豐常重要的。若是你答錯了這個問題,你也就到了得不到這份工做的邊緣。
評價下面的代碼片段:
unsigned int zero = 0;
unsigned int compzero = 0xFFFF;
/*1's complement of zero */ 0的補碼爲全1的數
對於一個int型不是16位的處理器爲說,上面的代碼是不正確的。應編寫以下:
unsigned int compzero = ~0;
這一問題真正能揭露出應試者是否懂得處理器字長的重要性(嵌入式平臺多是8、16、32的,移植的角度來講寫出固定的0xFFFF是不對的)。在個人經驗裏,好的嵌入式程序員很是準確地明白硬件的細節和它的侷限,然而PC機程序每每把硬件做爲一個沒法避免的煩惱。
到了這個階段,應試者或者徹底垂頭喪氣了或者信心滿滿志在必得。若是顯然應試者不是很好,那麼這個測試就在這裏結束了。但若是顯然應試者作得不錯,那麼我就扔出下面的追加問題,這些問題是比較難的,我想僅僅很是優秀的應試者能作得不錯。提出這些問題,我但願更多看到應試者應付問題的方法(很重要哦,面試者關注的是你思考問題解決問題的過程,當你不知道答案時千萬千萬不要猜一個答案給他,由於如今不是選擇題,面試官要的是過程,你只須要將你考慮問題的過程說明白就OK了),而不是答案。無論如何,你就當是這個娛樂吧...
儘管不像非嵌入式計算機那麼常見,嵌入式系統仍是有從堆(heap)中動態分配內存的過程的。那麼嵌入式系統中,動態分配內存可能發生的問題是什麼?這裏,我指望應試者能提到內存碎片,碎片收集的問題,變量的持行時間等等。這個主題已經在ESP雜誌中被普遍地討論過了(主要是 P.J. Plauger,他的解釋遠遠超過我這裏能提到的任何解釋),全部回過頭看一下這些雜誌吧!讓應試者進入一種虛假的安全感受後,我拿出這麼一個小節目:下面的代碼片斷的輸出是什麼,爲何?
char *ptr;
if ((ptr = (char *)malloc(0)) == NULL)
puts("Got a null pointer");
else
puts("Got a valid pointer");
這是一個有趣的問題。最近在個人一個同事不經意把0值傳給了函數malloc,獲得了一個合法的指針以後,我纔想到這個問題。這就是上面的代碼,該代碼的輸出是"Got a valid pointer"。我用這個來開始討論這樣的一問題,看看被面試者是否想到庫例程這樣作是正確(由於若是申請失敗,則程序處理認爲內存不足了,通常會終止程序,是很嚴重的問題?)。獲得正確的答案當然重要,但解決問題的方法和你作決定的基本原理更重要些。
返回一個控指針還是指向 0 字節的指針甚至指向一個能夠操做的指針?
(取決於系統平臺的實現,C99及其餘標準規定能夠不一樣的)
malloc(0) in glibc returns a valid pointer to something(!?!?) while in uClibc calling malloc(0) returns a NULL. The behavior of malloc(0) is listed as implementation-defined by SuSv3, so both libraries are equally correct. This difference also applies to realloc(NULL, 0). I personally feel glibc's behavior is not particularly safe. To enable glibc behavior, one has to explicitly enable the MALLOC_GLIBC_COMPAT option.
在C語言中頻繁用以聲明一個已經存在的數據類型的同義字。也能夠用預處理器作相似的事。例如,思考一下下面的例子:
#define dPS struct s *
typedef struct s * tPS;
以上兩種狀況的意圖都是要定義dPS 和 tPS 做爲一個指向結構s指針。哪一種方法更好呢?(若是有的話)爲何?
這是一個很是微妙的問題,任何人答對這個問題(正當的緣由哦,而不是猜,若是你沒有緣由,說不會比猜一個答案要好的多,記住啊,說話是要講根據的)是應當被恭喜的。答案是:typedef更好。思考下面的例子:
dPS p1,p2;
tPS p3,p4;
第一個擴展爲
struct s * p1, p2;
上面的代碼定義p1爲一個指向結構的指,p2爲一個實際的結構,這也許不是你想要的。第二個例子正確地定義了p3 和p4 兩個指針。
C語言贊成一些使人震驚的結構,下面的結構是合法的嗎,若是是它作些什麼?
int a = 5, b = 7, c;
c = a+++b;
這個問題將作爲這個測驗的一個愉快的結尾。無論你相不相信,上面的例子是徹底合乎語法的。問題是編譯器如何處理它?水平不高的編譯做者實際上會爭論這個問題,編譯器應儘量多的從左至右將若干個字符組成一個運算符。所以,上面的代碼被處理成:c = a++ + b;
逗號表達式依次對每一個表達式計算,最後的結果爲最後一個表達式的值
所以, 這段代碼執行後a = 6, b = 7, c = 12。
若是你知道答案,或猜出正確答案,作得好。若是你不知道答案,我也不把這個看成問題。我發現這個問題的最大好處是這是一個關於代碼編寫風格(要明確的加上括號,避免歧義或者編譯器不一樣帶來的差別),代碼的可讀性,代碼的可修改性的好的話題。
注:引出代碼風格的問題正是做者問此問題的目的,這告訴咱們要揣摩面試管每一個問題背後隱藏的考查點,可以趁機發揮下就大功告成了!
好了,夥計們,你如今已經作完全部的測試了。這就是我出的C語言測試題,我懷着愉快的心情寫完它,但願你以一樣的心情讀完它。若是是認爲這是一個好的測試,那麼儘可能都用到你的找工做的過程當中去吧。天知道也許過個一兩年,我就不作如今的工做,也須要找一個。
如下爲上述16個問題的英文表述,熟悉下相關的專業詞彙對於英文面試的簡單表述很重要。
http://www.yuanma.org/data/2007/0509/article_2585.htm
An obligatory and significant part of the recruitment process for embedded systems programmers seems to be the "C test." Over the years, I have had to both take and prepare such tests and, in doing so, have realized that these tests can be informative for both the interviewer and interviewee. Furthermore, when given outside the pressure of an interview situation, these tests can also be quite entertaining.
From the interviewee's perspective, you can learn a lot about the person who has written or administered the test. Is the test designed to show off the writer's knowledge of the minutiae of the ANSI standard rather than to test practical know-how? Does it test ludicrous knowledge, such as the ASCII values of certain characters? Are the questions heavily slanted towards your knowledge of system calls and memory allocation strategies, indicating that the writer may spend his time programming computers instead of embedded systems? If any of these are true, then I know I would seriously doubt whether I want the job in question.
From the interviewer's perspective, a test can reveal several things about the candidate. Primarily, you can determine the level of the candidate's knowledge of C. However, it's also interesting to see how the person responds to questions to which they don't know the answers. Do they make intelligent choices backed up with good intuition, or do they just guess? Are they defensive when they are stumped, or do they exhibit a real curiosity about the problem and see it as an opportunity to learn something? I find this information as useful as their raw performance on the test.
With these ideas in mind, I have attempted to construct a test that is heavily slanted towards the requirements of embedded systems. This is a lousy test to give to someone seeking a job writing compilers! The questions are almost all drawn from situations I have encountered over the years. Some of them are tough; however, they should all be informative.
This test may be given to a wide range of candidates. Most entry-level applicants will do poorly on this test, while seasoned veterans should do very well. Points are not assigned to each question, as this tends to arbitrarily weight certain questions. However, if you choose to adapt this test for your own uses, feel free to assign scores.
Preprocessor
1. Using the #define statement, how would you declare a manifest constant that returns the number of seconds in a year? Disregard leap years in your answer.
#define SECONDS_PER_YEAR
(60 * 60 * 24 * 365)UL
I'm looking for several things here:
Basic knowledge of the #define syntax (for example, no semi-colon at the end, the need to parenthesize, and so on)
An understanding that the pre-processor will evaluate constant expressions for you. Thus, it is clearer, and penalty-free, to spell out how you are calculating the number of seconds in a year, rather than actually doing the calculation yourself
A realization that the expression will overflow an integer argument on a 16-bit machine-hence the need for the L, telling the compiler to treat the variable as a Long
As a bonus, if you modified the expression with a UL (indicating unsigned long), then you are off to a great start. And remember, first impressions count!
2. Write the "standard" MIN macro-that is, a macro that takes two arguments and returns the smaller of the two arguments.
#define MIN(A,B)
((A)
<
= (B) ? (A) : (B))
The purpose of this question is to test the following:
Basic knowledge of the #define directive as used in macros. This is important because until the inline operator becomes part of standard C, macros are the only portable way of generating inline code. Inline code is often necessary in embedded systems in order to achieve the required performance level
Knowledge of the ternary conditional operator. This operator exists in C because it allows the compiler to produce more optimal code than an if-then-else sequence. Given that performance is normally an issue in embedded systems, knowledge and use of this construct is important
Understanding of the need to very carefully parenthesize arguments to macros
I also use this question to start a discussion on the side effects of macros, for example, what happens when you write code such as:
least = MIN(*p++, b);
3. What is the purpose of the preprocessor directive #error?
Either you know the answer to this, or you don't. If you don't, see Reference 1. This question is useful for differentiating between normal folks and the nerds. Only the nerds actually read the appendices of C textbooks to find out about such things. Of course, if you aren't looking for a nerd, the candidate better hope she doesn't know the answer.
Infinite loops
4. Infinite loops often arise in embedded systems. How does you code an infinite loop in C?
There are several solutions to this question. My preferred solution is:
while(1)
{
�
}
Many programmers seem to prefer:
for(;;)
{
�
}
This construct puzzles me because the syntax doesn't exactly spell out what's going on. Thus, if a candidate gives this as a solution, I'll use it as an opportunity to explore their rationale for doing so. If their answer is basically, "I was taught to do it this way and I haven't thought about it since," it tells me something (bad) about them.
A third solution is to use a goto :
Loop:
...
goto Loop;
Candidates who propose this are either assembly language programmers (which is probably good), or else they are closet BASIC/FORTRAN programmers looking to get into a new field.
Data declarations
5. Using the variable a, give definitions for the following:
a) An integer
b) A pointer to an integer
c) A pointer to a pointer to an integer
d) An array of 10 integers
e) An array of 10 pointers to integers
f) A pointer to an array of 10 integers
g) A pointer to a function that takes an integer as an argument and returns an integer
h) An array of ten pointers to functions that take an integer argument and return an integer
The answers are:
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
People often claim that a couple of these are the sorts of thing that one looks up in textbooks-and I agree. While writing this article, I consulted textbooks to ensure the syntax was correct. However, I expect to be asked this question (or something close to it) when I'm being interviewed. Consequently, I make sure I know the answers, at least for the few hours of the interview. Candidates who don't know all the answers (or at least most of them) are simply unprepared for the interview. If they can't be prepared for the interview, what will they be prepared for?
Static
6. What are the uses of the keyword static?
This simple question is rarely answered completely. Static has three distinct uses in C:
A variable declared static within the body of a function maintains its value between function invocations
A variable declared static within a module, (but outside the body of a function) is accessible by all functions within that module. It is not accessible by functions within any other module. That is, it is a localized global
Functions declared static within a module may only be called by other functions within that module. That is, the scope of the function is localized to the module within which it is declared
Most candidates get the first part correct. A reasonable number get the second part correct, while a pitiful number understand the third answer. This is a serious weakness in a candidate, since he obviously doesn't understand the importance and benefits of localizing the scope of both data and code.
Const
7. What does the keyword const mean?
As soon as the interviewee says "const means constant," I know I'm dealing with an amateur. Dan Saks has exhaustively covered const in the last year, such that every reader of ESP should be extremely familiar with what const can and cannot do for you. If you haven't been reading that column, suffice it to say that const means "read-only." Although this answer doesn't really do the subject justice, I'd accept it as a correct answer. (If you want the detailed answer, read Saks' columns-carefully!)
If the candidate gets the answer correct, I'll ask him these supplemental questions:
What do the following declarations mean?
const int a;
int const a;
const int *a;
int * const a;
int const * a const;
The first two mean the same thing, namely a is a const (read-only) integer. The third means a is a pointer to a const integer (that is, the integer isn't modifiable, but the pointer is). The fourth declares a to be a const pointer to an integer (that is, the integer pointed to by a is modifiable, but the pointer is not). The final declaration declares a to be a const pointer to a const integer (that is, neither the integer pointed to by a, nor the pointer itself may be modified). If the candidate correctly answers these questions, I'll be impressed. Incidentally, you might wonder why I put so much emphasis on const, since it is easy to write a correctly functioning program without ever using it. I have several reasons:
The use of const conveys some very useful information to someone reading your code. In effect, declaring a parameter const tells the user about its intended usage. If you spend a lot of time cleaning up the mess left by other people, you'll quickly learn to appreciate this extra piece of information. (Of course, programmers who use const , rarely leave a mess for others to clean up.)
const has the potential for generating tighter code by giving the optimizer some additional information
Code that uses const liberally is inherently protected by the compiler against inadvertent coding constructs that result in parameters being changed that should not be. In short, they tend to have fewer bugs
Volatile
8. What does the keyword volatile mean? Give three different examples of its use.
A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the optimizer must be careful to reload the variable every time it is used instead of holding a copy in a register. Examples of volatile variables are:
Hardware registers in peripherals (for example, status registers)
Non-automatic variables referenced within an interrupt service routine
Variables shared by multiple tasks in a multi-threaded application
Candidates who don't know the answer to this question aren't hired. I consider this the most fundamental question that distinguishes between a C programmer and an embedded systems programmer. Embedded folks deal with hardware, interrupts, RTOSes, and the like. All of these require volatile variables. Failure to understand the concept of volatile will lead to disaster.
On the (dubious) assumption that the interviewee gets this question correct, I like to probe a little deeper to see if they really understand the full significance of volatile . In particular, I'll ask them the following additional questions:
Can a parameter be both const and volatile ? Explain.
Can a pointer be volatile ? Explain.
What's wrong with the following function?:
int square(volatile int *ptr)
{
return *ptr * *ptr;
}
The answers are as follows:
Yes. An example is a read-only status register. It is volatile because it can change unexpectedly. It is const because the program should not attempt to modify it
Yes, although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer
This one is wicked. The intent of the code is to return the square of the value pointed to by *ptr . However, since *ptr points to a volatile parameter, the compiler will generate code that looks something like this:
int square(volatile int *ptr)
{
int a,b;
a = *ptr;
b = *ptr;
return a * b;
}
Because it's possible for the value of *ptr to change unexpectedly, it is possible for a and b to be different. Consequently, this code could return a number that is not a square! The correct way to code this is:
long square(volatile int *ptr)
{
int a;
a = *ptr;
return a * a;
}
Bit manipulation
9. Embedded systems always require the user to manipulate bits in registers or variables. Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.
These are the three basic responses to this question:
No idea. The interviewee cannot have done any embedded systems work
Use bit fields. Bit fields are right up there with trigraphs as the most brain-dead portion of C. Bit fields are inherently non-portable across compilers, and as such guarantee that your code is not reusable. I recently had the misfortune to look at a driver written by Infineon for one of their more complex communications chips. It used bit fields and was completely useless because my compiler implemented the bit fields the other way around. The moral: never let a non-embedded person anywhere near a real piece of hardware!
Use #defines and bit masks. This is a highly portable method and is the one that should be used. My optimal solution to this problem would be:
#define BIT3 (0x1 << 3)
static int a;
void set_bit3(void) {
a |= BIT3;
}
void clear_bit3(void) {
a &= ~BIT3;
}
Some people prefer to define a mask together with manifest constants for the set and clear values. This is also acceptable. The element that I'm looking for is the use of manifest constants, together with the |= and &= ~ constructs
Accessing fixed memory locations
10. Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.
This problem tests whether you know that it is legal to typecast an integer to a pointer in order to access an absolute location. The exact syntax varies depending upon one's style. However, I would typically be looking for something like this:
int *ptr;
ptr = (int *)0x67a9;
*ptr = 0xaa55;
A more obscure approach is:
*(int * const)(0x67a9) = 0xaa55;
Even if your taste runs more to the second solution, I suggest the first solution when you are in an interview situation.
Interrupts
11. Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new keyword is __interrupt. The following code uses __interrupt to define an interrupt service routine (ISR). Comment on the code.
__interrupt double compute_area
(double
radius)
{
double area = PI * radius *
radius;
printf("/nArea = %f", area);
return area;
}
This function has so much wrong with it, it's hard to know where to start:
ISRs cannot return a value. If you don't understand this, you aren't hired
ISRs cannot be passed parameters. See the first item for your employment prospects if you missed this
On many processors/compilers, floating-point operations are not necessarily re-entrant. In some cases one needs to stack additional registers. In other cases, one simply cannot do floating point in an ISR. Furthermore, given that a general rule of thumb is that ISRs should be short and sweet, one wonders about the wisdom of doing floating-point math here
In a vein similar to the third point, printf() often has problems with reentrancy and performance. If you missed points three and four, I wouldn't be too hard on you. Needless to say, if you got these last two points, your employment prospects are looking better and better
Code examples
12. What does the following code output and why?
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") :
puts("
<
= 6");
}
This question tests whether you understand the integer promotion rules in C-an area that I find is very poorly understood by many developers. Anyway, the answer is that this outputs "> 6." The reason for this is that expressions involving signed and unsigned types have all operands promoted to unsigned types. Thus �20 becomes a very large positive integer and the expression evaluates to greater than 6. This is a very important point in embedded systems where unsigned data types should be used frequently (see Reference 2). If you get this one wrong, you are perilously close to not getting the job.
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. Anyway, have fun...
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)
else
puts("Got a null pointer");
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.
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.
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.
Nigel Jones is a consultant living in Maryland. When not underwater, he can be found slaving away on a diverse range of embedded projects. He enjoys hearing from readers and can be reached at NAJones@compuserve.com .
References
Jones, Nigel, "In Praise of the #error directive," Embedded Systems Programming, September 1999, p. 114.
Jones, Nigel, " Efficient C Code for Eight-bit MCUs ," Embedded Systems Programming, November 1998, p. 66.