user-0 提问: 很简单的问题:如何定义定长的常量数组.

回复:
user: user-1
content: http://bbs.csdn.net/topics/380157851

user: user-0
content: 谢谢 zhao4zhong1 赵4老师 提醒

user: user-0
content: 谢谢  zilaishuichina, 赵4老师, 也谢谢 xihu1364 基本解决了我疑问. 只想找一种方便的写法. 没想到还是没有捷径。 但又学到一些  看看我这个代码还有优化的地方吗? 我自己 觉得很不错了.速度应该没比这个再快了(除了汇编)  //十进制转二进制 BSTR __stdcall DecToBin(long Number, long Places) { 	static __int64 DEC_BIN[16]={0x0030003000300030,0x0031003000300030,0x0030003100300030,0x0031003100300030,0x0030003000310030,0x0031003000310030,0x0030003100310030,0x0031003100310030,0x0030003000300031,0x0031003000300031,0x0030003100300031,0x0031003100300031,0x0030003000310031,0x0031003000310031,0x0030003100310031,0x0031003100310031}; 	__int64 wRet[8]={0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030};  	wRet[0]=DEC_BIN[(Number & 0xF0000000) >> 28]; 	wRet[1]=DEC_BIN[(Number & 0x0F000000) >> 24]; 	wRet[2]=DEC_BIN[(Number & 0x00F00000) >> 20]; 	wRet[3]=DEC_BIN[(Number & 0x000F0000) >> 16]; 	wRet[4]=DEC_BIN[(Number & 0x0000F000) >> 12]; 	wRet[5]=DEC_BIN[(Number & 0x00000F00) >> 8]; 	wRet[6]=DEC_BIN[(Number & 0x000000F0) >> 4]; 	wRet[7]=DEC_BIN[Number & 0x0000000F];  	//返回bstr数据 	return SysAllocStringLen((OLECHAR*)wRet, Places); }

user: user-2
content: 楼主 你就  wchar_t DEC_BIN[16][5] = {{'0','0','0','0'},....} 了

user: user-2
content: 哦 是wchar_t DEC_BIN[16][4]

user: user-3
content: 引用 9 楼 topses 的回复:[quote=引用 7 楼 qq_30900077 的回复:] 用用这个吧  wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};  无语了....比我还菜的人有这多么多........ wchar_t* DEC_BIN....这个申明的是指针数组,日....不是我要的. 定长数组不懂吗?  要求, 申明一个元素为16字节长的数组就这么简单  三楼的是连续内存块,但老是多一个\0字符 const char DEC_BIN[16][5] = { "0000", "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009", "000A", "000B", "000C", "000D", "000E", "000F" }; [/quote]  多一个\0 是因为你用的字符串， "0000"你这样写，就是带\0的只是你看不见， 你不想要\0，就不要定义成字符串

user: user-1
content: const wchar_t DEC_BIN[16][4]={     {L'0',L'0',L'0',L'0'},     {L'0',L'0',L'0',L'1'},     {L'0',L'0',L'0',L'2'},     {L'0',L'0',L'0',L'3'},     {L'0',L'0',L'0',L'4'},     {L'0',L'0',L'0',L'5'},     {L'0',L'0',L'0',L'6'},     {L'0',L'0',L'0',L'7'},     {L'0',L'0',L'0',L'8'},     {L'0',L'0',L'0',L'9'},     {L'0',L'0',L'0',L'A'},     {L'0',L'0',L'0',L'B'},     {L'0',L'0',L'0',L'C'},     {L'0',L'0',L'0',L'D'},     {L'0',L'0',L'0',L'E'},     {L'0',L'0',L'0',L'F'}, };

user: user-0
content: 引用 7 楼 qq_30900077 的回复:用用这个吧  wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};  无语了....比我还菜的人有这多么多........ wchar_t* DEC_BIN....这个申明的是指针数组,日....不是我要的. 定长数组不懂吗?  要求, 申明一个元素为16字节长的数组就这么简单  三楼的是连续内存块,但老是多一个\0字符 const char DEC_BIN[16][5] = { "0000", "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009", "000A", "000B", "000C", "000D", "000E", "000F" };

user: user-3
content: 引用 6 楼 topses 的回复:我的要求很简单 在C中实现定长数组, 如果VB中dim FixedStr(15) as  string * 8  你们看,我只想用 wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};   完成下面的功能 __int64 DEC_BIN[16] = {0x30003000300030,0x30003000300031,0x30003000310030,0x30003000310031,0x30003100300030.......  上面是8字节为一组还好有int64对应,但如遇到16字节一组那咋写  const unsigned char DEC_BIN[16 * 8] = {  		0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00,  		0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 		0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 0x30, 0x00, 		0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 		0x30, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 		0x30, 0x00, 0x31, 0x00, 0x30, 0x00, 0x31, 0x00, 		0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 		0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 		0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 		0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 		0x31, 0x00, 0x30, 0x00, 0x31, 0x00, 0x30, 0x00, 		0x31, 0x00, 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 		0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 		0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x31, 0x00, 		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 	};

user: user-4
content: 用用这个吧  wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};

user: user-0
content: 我的要求很简单 在C中实现定长数组, 如果VB中dim FixedStr(15) as  string * 8  你们看,我只想用 wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};   完成下面的功能 __int64 DEC_BIN[16] = {0x30003000300030,0x30003000300031,0x30003000310030,0x30003000310031,0x30003100300030.......  上面是8字节为一组还好有int64对应,但如遇到16字节一组那咋写

user: user-0
content: 引用 2 楼 xihu1364 的回复:[quote=引用 楼主 topses 的回复:] 很简单的问题:如何定义定长的常量数组.   const wchar_t DEC_BIN[15]={"0000","0001","0002","0003","0004","0005","0006","0007","0008","0009","000A","000B","000C","000D","000E","000F"};  以上编译失败,帮我指点一下.  楼主，你这数组成员都是字符串啊  const wchar_t DEC_BIN[3]={0x00,0x01,0x02} 想这样？ 还是 const wchar_t DEC_BIN[3]={’0‘,’1‘,’2‘} ？[/quote]  我成员 是字符串, 但我想申明为连续的内存块. 版主你的只能单个字符  帮我看看下面的, 申明不是连续内存块.我要的是连续的内存块 wchar_t* DEC_BIN[16] = {L"0000",L"0001",L"0010",L"0011",L"0100",L"0101",L"0110",L"0111",L"1000",L"1001",L"1010",L"1011",L"1100",L"1101",L"1110",L"1111"};

user: user-0
content: 我是想申明为连续的内存块, 二楼的不行

user: user-3
content: const char DEC_BIN[16][5] = { "0000", "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009", "000A", "000B", "000C", "000D", "000E", "000F" };

user: user-2
content: 引用 楼主 topses 的回复:很简单的问题:如何定义定长的常量数组.   const wchar_t DEC_BIN[15]={"0000","0001","0002","0003","0004","0005","0006","0007","0008","0009","000A","000B","000C","000D","000E","000F"};  以上编译失败,帮我指点一下.  楼主，你这数组成员都是字符串啊  const wchar_t DEC_BIN[3]={0x00,0x01,0x02} 想这样？ 还是 const wchar_t DEC_BIN[3]={’0‘,’1‘,’2‘} ？

user: user-5
content: const char* DEC_BIN[16] = {"0000","0001","0002","0003","0004","0005","0006","0007","0008","0009","000A","000B","000C","000D","000E","000F"};  要用 wchar_t 的话，后面的初始值需要用 L.

user: user-1
content: 引用 16 楼 topses 的回复:呵呵 10楼写起来会要了你命 我支持8楼和我自己的.这样直接在EXCEL模板里鼠标动动, 代码就生成了.  BSTR __stdcall DecToBin(long Number, long Places) { 	static __int64 DEC_BIN[16]={0x0030003000300030,0x0031003000300030,0x0030003100300030,0x0031003100300030,0x0030003000310030,0x0031003000310030,0x0030003100310030,0x0031003100310030,0x0030003000300031,0x0031003000300031,0x0030003100300031,0x0031003100300031,0x0030003000310031,0x0031003000310031,0x0030003100310031,0x0031003100310031}; 	__int64 wRet[8]={0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030};  	wRet[0]=DEC_BIN[(Number & 0xF0000000) >> 28]; 	wRet[1]=DEC_BIN[(Number & 0x0F000000) >> 24]; 	wRet[2]=DEC_BIN[(Number & 0x00F00000) >> 20]; 	wRet[3]=DEC_BIN[(Number & 0x000F0000) >> 16]; 	wRet[4]=DEC_BIN[(Number & 0x0000F000) >> 12]; 	wRet[5]=DEC_BIN[(Number & 0x00000F00) >> 8]; 	wRet[6]=DEC_BIN[(Number & 0x000000F0) >> 4]; 	wRet[7]=DEC_BIN[Number & 0x0000000F];  	//修正占位符的长度 	short *wTmp = (short*)wRet; 	if ((Places < 1) || (Places > 32)) 	{	 		while(*wTmp == 0x30)  wTmp++;  		Places = 32 - (wTmp - (short*)wRet);  		if (Places <= 0)  Places = 1, wTmp--; 	}; 	//返回bstr数据 	return SysAllocStringLen((OLECHAR*)wTmp, Places); }  为了调整占用位符,这行代码,花了我整整1个小时.唉 那只是因为你用的编辑器不给力。 BSTR __stdcall DecToBin(long Number, long Places) {     static __int64 DEC_BIN[16]={         0x0030003000300030i64,         0x0031003000300030i64,         0x0030003100300030i64,         0x0031003100300030i64,         0x0030003000310030i64,         0x0031003000310030i64,         0x0030003100310030i64,         0x0031003100310030i64,         0x0030003000300031i64,         0x0031003000300031i64,         0x0030003100300031i64,         0x0031003100300031i64,         0x0030003000310031i64,         0x0031003000310031i64,         0x0030003100310031i64,         0x0031003100310031i64,     };     __int64 wRet[8]={         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,         0x0030003000300030i64,     };     wRet[0]=DEC_BIN[(Number & 0xF0000000) >> 28];     wRet[1]=DEC_BIN[(Number & 0x0F000000) >> 24];     wRet[2]=DEC_BIN[(Number & 0x00F00000) >> 20];     wRet[3]=DEC_BIN[(Number & 0x000F0000) >> 16];     wRet[4]=DEC_BIN[(Number & 0x0000F000) >> 12];     wRet[5]=DEC_BIN[(Number & 0x00000F00) >>  8];     wRet[6]=DEC_BIN[(Number & 0x000000F0) >>  4];     wRet[7]=DEC_BIN[(Number & 0x0000000F)      ];     //修正占位符的长度     short *wTmp = (short*)wRet;     if ((Places < 1) || (Places > 32)) {         while (*wTmp == 0x30)  wTmp++;         Places = 32 - (wTmp - (short*)wRet);         if (Places <= 0)  {Places = 1; wTmp--;}     }     //返回bstr数据     return SysAllocStringLen((OLECHAR*)wTmp,Places); }

user: user-0
content: 呵呵 10楼写起来会要了你命 我支持8楼和我自己的.这样直接在EXCEL模板里鼠标动动, 代码就生成了.  BSTR __stdcall DecToBin(long Number, long Places) { 	static __int64 DEC_BIN[16]={0x0030003000300030,0x0031003000300030,0x0030003100300030,0x0031003100300030,0x0030003000310030,0x0031003000310030,0x0030003100310030,0x0031003100310030,0x0030003000300031,0x0031003000300031,0x0030003100300031,0x0031003100300031,0x0030003000310031,0x0031003000310031,0x0030003100310031,0x0031003100310031}; 	__int64 wRet[8]={0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030,0x0030003000300030};  	wRet[0]=DEC_BIN[(Number & 0xF0000000) >> 28]; 	wRet[1]=DEC_BIN[(Number & 0x0F000000) >> 24]; 	wRet[2]=DEC_BIN[(Number & 0x00F00000) >> 20]; 	wRet[3]=DEC_BIN[(Number & 0x000F0000) >> 16]; 	wRet[4]=DEC_BIN[(Number & 0x0000F000) >> 12]; 	wRet[5]=DEC_BIN[(Number & 0x00000F00) >> 8]; 	wRet[6]=DEC_BIN[(Number & 0x000000F0) >> 4]; 	wRet[7]=DEC_BIN[Number & 0x0000000F];  	//修正占位符的长度 	short *wTmp = (short*)wRet; 	if ((Places < 1) || (Places > 32)) 	{	 		while(*wTmp == 0x30)  wTmp++;  		Places = 32 - (wTmp - (short*)wRet);  		if (Places <= 0)  Places = 1, wTmp--; 	}; 	//返回bstr数据 	return SysAllocStringLen((OLECHAR*)wTmp, Places); }  为了调整占用位符,这行代码,花了我整整1个小时.唉

user: user-6
content: 支持10楼的