Q: big endian vs little endian, how to check ?
sample code:
int main(void)
{
short int a = 0x1234;
char *p = (char *)&a;
printf("p=%#hhx\n",*p);
if(*p == 0x34)
printf("Little endian \n");
else if(*p == 0x12)
printf("Big endian \n");
else
printf("Unknow endian \n");
return 0;
}
2015年6月9日 星期二
C語言 - sizeof(), strlen()
static void tim_test(void)
{
char str1[]="12345\n";
char *p1=str1;
UINT8 a,b,c,d,e;
a=sizeof(str1);
b=sizeof(p1);
c=sizeof(*p1);
d=strlen(str1);
e=strlen(p1);
libc_printf("%s(): a=%u, b=%u, c=%u, d=%u, e=%u \n",__FUNCTION__,a,b,c,d,e);
}
/*
sizeof(str1)=? 7 ("有"包括terminated null character)
sizeof(p1)=? 4 (指標變數)
sizeof(*p1)=? 1 char型態的指標 1 byte
*/
--
程式輸出:
tim_test(): a=7, b=4, c=1, d=6, e=6
C語言 - printf str pointer
void tim_test_str_printf(void)
{
char *str = "abcde";
libc_printf("%s(): str = %s, *str=%c \n",__FUNCTION__,str,*str);
}
/*
*str --> 1 byte, char型態的指標
%s: 印出string
%c: 印出一個character
*/
程式輸出:
tim_test_str_printf(): str = abcde, *str=a
--
面試被問到 紀錄一下
2014年3月22日 星期六
2013年4月25日 星期四
C語言 - gcc: error: macro names must be identifiers
這個錯誤是指說當code中使用 #ifdef XXX 時 XXX不可以為數字開頭
The #ifdef directive is used to check if a pre-processor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit.
ex.
#ifdef 123_SUPPORT -> /* error!!! */
.
.
.
#endif
正確的:
#ifdef TEST_123_SUPPORT -> /* ok!!!! */
.
.
.
#endif
The #ifdef directive is used to check if a pre-processor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit.
ex.
#ifdef 123_SUPPORT -> /* error!!! */
.
.
.
#endif
正確的:
#ifdef TEST_123_SUPPORT -> /* ok!!!! */
.
.
.
#endif
Reference:
2013年4月5日 星期五
DVB-T, Hierarchical modulation
DVB-T有個特殊得功能稱之為 hierarchical mode, 也就是說以原本通常使用在同個TP中間去帶節目資訊都是在high priority的部分, 如果今天想在原本的TP部分把low priority的部分拿來帶節目的話的這功能稱之為 hierarchical mode. 這優點就是如果有這功能的話可以在原本的TP中去多帶一倍的節目 但這功能現在普遍是很少在使用
有兩種mode, priority high/low, default是採用priority high的模式
Reference:
有兩種mode, priority high/low, default是採用priority high的模式
Reference:
2013年3月18日 星期一
C語言 - i++ vs. ++i
結果而言是相同,只是過程不同
i++:是先顯示i後再去做+1
++i:則是先做+1後再顯示
[1] [2]有例子寫得很好
以compiler而言,++i的效能會比較好[3]
[1] http://lagunawang.pixnet.net/blog/post/10425717-i%2B%2B-%E8%88%87-%2B%2Bi-%E7%9A%84%E5%B7%AE%E5%88%A5
[2] http://blog.roodo.com/sayaku/archives/14912893.html
[3] http://www.programmer-club.com.tw/showSameTitleN/homework/4354.html
i++:是先顯示i後再去做+1
++i:則是先做+1後再顯示
[1] [2]有例子寫得很好
以compiler而言,++i的效能會比較好[3]
[1] http://lagunawang.pixnet.net/blog/post/10425717-i%2B%2B-%E8%88%87-%2B%2Bi-%E7%9A%84%E5%B7%AE%E5%88%A5
[2] http://blog.roodo.com/sayaku/archives/14912893.html
[3] http://www.programmer-club.com.tw/showSameTitleN/homework/4354.html
訂閱:
文章 (Atom)
