一○○分请教一问题

aaa198416aaaa 2006-05-31 11:38:24
#在宏里使用,这个符号是什么意思,有什么用?



CRITICAL_SECTION g_cs; //阻塞模式
bool g_bThreadSafe = true;

inline DXUTLock() { if( g_bThreadSafe ) EnterCriticalSection( &g_cs ); }

#define SET_ACCESSOR( x, y ) inline void Set##y( x t ) { DXUTLock l; m_state.m_##y = t; };

这个宏是什么意思?##起什么作用呢?
...全文
104 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hslinux 2006-05-31
  • 打赏
  • 举报
回复
Token-Pasting Operator (##)
The double-number-sign or “token-pasting” operator (##), which is sometimes called the “merging” operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token and therefore cannot be the first or last token in the macro definition.

If a formal parameter in a macro definition is preceded or followed by the token-pasting operator, the formal parameter is immediately replaced by the unexpanded actual argument. Macro expansion is not performed on the argument prior to replacement.

Then, each occurrence of the token-pasting operator in token-string is removed, and the tokens preceding and following it are concatenated. The resulting token must be a valid token. If it is, the token is scanned for possible replacement if it represents a macro name. The identifier represents the name by which the concatenated tokens will be known in the program before replacement. Each token represents a token defined elsewhere, either within the program or on the compiler command line. White space preceding or following the operator is optional.

This example illustrates use of both the stringizing and token-pasting operators in specifying program output:

#define paster( n ) printf( "token" #n " = %d", token##n )
int token9 = 9;

If a macro is called with a numeric argument like

paster( 9 );

the macro yields

printf( "token" "9" " = %d", token9 );

which becomes

printf( "token9 = %d", token9 );

乔小布 2006-05-31
  • 打赏
  • 举报
回复
JF
吃狼的豆腐 2006-05-31
  • 打赏
  • 举报
回复
#,##
# 和 ## 操作符是和#define宏使用的. 使用# 使在#后的首个参数返回为一个带引号的字符串. 例如, 命令

#define to_string( s ) # s

将会使编译器把以下命令

cout << to_string( Hello World! ) << endl;

理解为

cout << "Hello World!" << endl;

使用##连结##前后的内容. 例如, 命令

#define concatenate( x, y ) x ## y
...
int xy = 10;
...

将会使编译器把

cout << concatenate( x, y ) << endl;

解释为

cout << xy << endl;

理所当然,将会在标准输出处显示'10'.
吃狼的豆腐 2006-05-31
  • 打赏
  • 举报
回复
##连接
#替换
jinjiajie 2006-05-31
  • 打赏
  • 举报
回复
##是表示连接!
ymx0330 2006-05-31
  • 打赏
  • 举报
回复
##是表示连接!
LZ慢慢品啊~~~
Z_X_H 2006-05-31
  • 打赏
  • 举报
回复
##表示连接.如:
#define Print(x) Print_##x
void Print_Int()
{
cout << "Print_Int()" << endl;
}
int main()
{
Print(Int)(); // 相当于调用函数Print_Int();
return 0;
}

输出结果: Print_Int
zez 2006-05-31
  • 打赏
  • 举报
回复
连接字符串!!!
#define SET_ACCESSOR( x, y ) inline void Set##y( x t ) { DXUTLock l; m_state.m_##y = t; };

SET_ACCESSOR(1, 2 )
inline void Set2( 1 t ) { DXUTLock l; m_state.m_2 = t; };
ouyh12345 2006-05-31
  • 打赏
  • 举报
回复
##是替换
铖邑 2006-05-31
  • 打赏
  • 举报
回复
是连接的意思。

#define SET_ACCESSOR( x, y ) inline void Set##y( x t ) { DXUTLock l; m_state.m_##y = t; };

SET_ACCESSOR( a, b )
相当于下面:
inline void Setb( a t ) { DXUTLock l; m_state.m_b = t; };
课程设计(论文) 题 目: 连连看游戏 姓名 学号 指导教师(签名) 二一一 年 七 月 十四 日 Java课程设计 摘要: “连连看”游戏是一个经典的游戏,它因操作简单、娱乐性强儿广受欢迎。我们通过所学的JAVAEE,设计了一个操作简凡、界面美观、功能较齐全的“连连看”游戏。 该游戏是用图形界面实现的,通过编译解释后,出现一个图开界面,界面是由若干个小方格组成的,每一个小方格里面有一个数值,如果在一个边上有相同的数值,连续点击它们就会消失,同时界面上正上方的数就会自动加。游戏还设有退出、重列、再来一局的功能,方便游戏操作。 通过本游戏的开发,达到学习JavaEE技术和熟悉软件开发流程的目的。 前言 近年来,JavaEE作为一种新的编程语言,以其简单性、可移植性和平台无关等优点,得到了广泛的应用,特别是JavaEE与万维网的完美结合,使其成为网络编程和嵌入式编程领域的首选编程语言。 以一个学期的时间来学习JAVAEE这门课,我们不但学习了书上理论的东西,还安排了上机操作课。我认为学习一门计算机语言必定离不开实践,只有通过实践我们才能体会到书本上体会不到的东西。所以,我们不仅要认真学习课本理论知识,更重要的是通过上机实践才能增强和巩固我的知识。课程设计是培养我们综合运用所学知识,发现、提出、析和解决实际问题,锻炼实践能力的重要环节,是我们实践能力与创新精神的综合培养:在实践能力方面培养我们理论与实践相结合的作风,增强了我们将来在人才市场上的竞争力。 所以,对于我们初学者,首先利用课程设计这样的小项目锻炼袭击的科学研究精神和提高创新能力,是很有必要的。 设计游戏时首先要理顺思路,开始要有一个清晰的可以表达清楚地思路是必不可缺的,游戏设计重点在于游戏有一个界面,方便游戏玩家使用,开始设计前就要想好要有一个什么样的界面此时就要稍微用到点审美力,以达到大多数玩家的审美水平,让更多人接受,因此首先要清楚先要做什么后要做什么,再次我们可以规划一下我们的步骤:首先做出一个流程图,然后对即将做出的游戏构思一个漂亮的界面,最后一步就是要写出我们的程序源代码。 一、让别人清楚你的思路以便在遇到困难时可以请教别人,更可以让自己做的得心应手,因此首先要做一个流程图:

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧