编译时最大strlen? [英] max strlen at compile time?
问题描述
我可以使用预处理器,使用sizeof(a)/ sizeof(a [0])来产生一个
错误太长的字符串?
喜欢:
#define CRYPT(a)\
#if sizeof(a)/ sizeof(a [0])31 \
xCRYPT(a)\
#else \
#error xy \
#endif
(这当然不起作用)
-
-Gernot
int main(int argc,char ** argv){printf
("%silto%c% cf%cgl%ssic%ccom%c"," ma",58,''g'',64," ba",46,10);}
________________________________________
想找个好游戏吗?亲自动手吧!
GLBasic - 你可以这样做
www.GLBasic .com
Gernot Frisch说:
>
我可以使用预处理器,使用sizeof(a)/ sizeof(a [0])来产生一个
错误太长的字符串?
不,预处理器没有解决sizeof的使用 - 这是由
编译器稍后完成的。 />
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
在文章< jK **** **************************@bt.com> ;,
Richard Heathfield< in ***** @ invalid.invalidwrote:
>我可以使用预处理器,使用sizeof(a)/ sizeof(a [0])太久的字符串会产生错误?
>不,预处理器无法解决sizeof的使用 - 这是由
完成的编译器稍后。
但是,sizeof确实产生一个常数值,并且过去在这里发布了
技巧来检测此类错误
编译时间。
- Richard
Richard Tobin说:
< blockquote class =post_quotes>
文章< jK ****************************** @ bt.com> ;,
Richard Heathfield< in ***** @ invalid.invalidwrote:
> ;>我可以使用预处理器,使用sizeof(a)/ sizeof(a [0])来为太长的字符串产生
错误吗?
>>不,预处理器无法解决sizeof的使用 - 这是由
编译器稍后。
但是,sizeof确实产生一个常数值,并且过去在这里发布过
技巧来检测此类错误
编译时间。
是的,但他特别询问了预处理器。 (是的,我知道,
主题行说编译时间......)
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
Hi,
can I use the preprocessor, using sizeof(a)/sizeof(a[0]) to yield an
error for too long strings?
Like:
#define CRYPT(a) \
#if sizeof(a)/sizeof(a[0]) 31 \
xCRYPT(a) \
#else\
#error xy\
#endif
(which of course doe not work)
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, ''g'', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Gernot Frisch said:
>
Hi,
can I use the preprocessor, using sizeof(a)/sizeof(a[0]) to yield an
error for too long strings?No, the preprocessor doesn''t resolve uses of sizeof - that''s done by the
compiler later on.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
In article <jK******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalidwrote:
>can I use the preprocessor, using sizeof(a)/sizeof(a[0]) to yield an
error for too long strings?
>No, the preprocessor doesn''t resolve uses of sizeof - that''s done by the
compiler later on.However, sizeof does produce a constant value, and there have been
tricks posted here in the past to detect errors of this kind at
compile time.
-- Richard
Richard Tobin said:
In article <jK******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalidwrote:
>>can I use the preprocessor, using sizeof(a)/sizeof(a[0]) to yield an
error for too long strings?
>>No, the preprocessor doesn''t resolve uses of sizeof - that''s done by the
compiler later on.
However, sizeof does produce a constant value, and there have been
tricks posted here in the past to detect errors of this kind at
compile time.Yes, but he specifically asked about the preprocessor. (Yeah, I know, the
subject line says "compile time"...)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
这篇关于编译时最大strlen?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!