這裏是我的代碼..如何獲得元素的總數在結構
#include <stdio.h>
struct new {
unsigned short b0 = 0;
unsigned short b1 = 0;
unsigned short b2 = 0;
unsigned short b3 = 0;
unsigned short b4 = 0;
unsigned short b5 = 0;
unsigned short b6 = 0;
unsigned short b7 = 0;
};
int main()
{
printf("Bit Field Example\n");
struct new b; //Seems wrong to me
int result = sizeof(b)/sizeof(*b); //Seems wrong to me
printf("Size: %d\n", result);
return 0;
}
我使用的是Linux機器來編譯代碼提及。我知道下面的行是錯誤的。但我不確定任何其他技術。我不知道下面的行是錯誤的。但我不確定任何其他技術。我不知道下面的行是錯誤的。但我不知道任何其他技術。我不知道下面的行是錯誤的。但我不知道任何其他技術。但我不知道下面的行是錯誤的。但我不知道任何其他技術。首先,是否可以統計結構中的元素總數?請給我一些關於如何去做的想法。
在此先感謝。
所以要根據你的,它不可能指望在結構元素的個數..對 ?那麼,是否可以使用數組定義位域?我的意思是,這將是正確的語法或其他... – 2013-04-04 11:31:09
嗯... Thnx的明確的例子..我發現我的錯誤... Thnx很多..但在這裏,還有一個問題出現,無論是否這些位字段可以類似於結構的元素訪問。 – 2013-04-04 11:38:45