社区
C语言
帖子详情
这个宏应该怎么写
mcawxd
2011-10-17 01:56:00
想定义一个类似于这样的宏
#define LOG __FILE__##hashcode
如果在c:\comAPI.cpp引用这个宏得到的结果将是 c:\comAPI.cpphashcode,我想得到的结果是comhashcode,就是把路径和.cpp等无用的字符去掉,得到的这个字符又作为一个新的宏,如:
#define comhashcode 0x123
请问这个LOG宏应该怎么写。
...全文
147
11
打赏
收藏
这个宏应该怎么写
想定义一个类似于这样的宏 #define LOG __FILE__##hashcode 如果在c:\comAPI.cpp引用这个宏得到的结果将是 c:\comAPI.cpphashcode,我想得到的结果是comhashcode,就是把路径和.cpp等无用的字符去掉,得到的这个字符又作为一个新的宏,如: #define comhashcode 0x123 请问这个LOG宏应该怎么写。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
东莞某某某
2011-10-17
打赏
举报
回复
写一个宏函数 从__FILE__中抽取名字
mcawxd
2011-10-17
打赏
举报
回复
[Quote=引用 1 楼 luciferisnotsatan 的回复:]
那就只能你自己写了。
#define LOG(FILENAME) FILENAME##hashcode
[/Quote]
我有很多cpp文件都会引用这个宏。来得到当前文件名并加一个hashcode,目的是为了在另一个头文件中得到对应的数值。如:comAPI.cpp使用这个宏时得到的是 0x123,com1API使用时得到的是0x456。
#define comhashcode 0x123
#define com1hashcode 0x456
crystal_avast
2011-10-17
打赏
举报
回复
修改后的得文件名方法:
LPCTSTR GetFileName()
{
CString csFilePath( _T( __FILE__ ));
int nPos = csFilePath.Find( _T( "." ), 0 );
CString csSubFilePath = csFilePath.Mid( 0, nPos );
int nStartPos = 0;
int nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos );
static CString csFileName;
while ( TRUE )
{
if ( nFindPos == -1 )
{
csFileName = csSubFilePath.Mid( nStartPos + 1 );
break;
}
nStartPos = nFindPos;
nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos + 1 );
}
return csFileName.operator LPCTSTR();
}
crystal_avast
2011-10-17
打赏
举报
回复
LPCTSTR GetFileName()
{
CString csFilePath( _T( __FILE__ ));
int nPos = csFilePath.Find( _T( "." ), 0 );
CString csSubFilePath = csFilePath.Mid( 0, nPos );
int nStartPos = 0;
int nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos );
static CString csFileName;
while ( TRUE )
{
nStartPos = nFindPos;
nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos + 1 );
if ( nFindPos == -1 )
{
csFileName = csSubFilePath.Mid( nStartPos + 1 );
break;
}
}
return csFileName.operator LPCTSTR();
}
crystal_avast
2011-10-17
打赏
举报
回复
我写了一个得到文件名的函数,是用CString实现的,或许对LZ有用
LPCTSTR GetFileName()
{
CString csFilePath( _T( __FILE__ ));
int nPos = csFilePath.Find( _T( "." ), 0 );
CString csSubFilePath = csFilePath.Mid( 0, nPos );
int nStartPos = 0;
int nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos );
static CString csFileName;
while ( TRUE )
{
nStartPos = nFindPos;
nFindPos = csSubFilePath.Find( _T( "\\" ), nStartPos + 1 );
if ( nFindPos == -1 )
{
csFileName = csSubFilePath.Mid( nStartPos + 1 );
break;
}
}
return csFileName.operator LPCTSTR();
}
赵4老师
2011-10-17
打赏
举报
回复
在c:\com*.cpp每个文件第一行加
#define LOG com##hashcode
lk1928
2011-10-17
打赏
举报
回复
引用 1 楼 luciferisnotsatan 的回复:]
那就只能你自己写了。
#define LOG(FILENAME) FILENAME##hashcode
[/Quote]
柯本
2011-10-17
打赏
举报
回复
另:
像这种需求就不会用宏了,在程序中实现吧
柯本
2011-10-17
打赏
举报
回复
[Quote=引用 2 楼 bdmh 的回复:]
引用 1 楼 luciferisnotsatan 的回复:
那就只能你自己写了。
#define LOG(FILENAME) FILENAME##hashcode
+1
[/Quote]
++
bdmh
2011-10-17
打赏
举报
回复
[Quote=引用 1 楼 luciferisnotsatan 的回复:]
那就只能你自己写了。
#define LOG(FILENAME) FILENAME##hashcode
[/Quote]
+1
luciferisnotsatan
2011-10-17
打赏
举报
回复
那就只能你自己写了。
#define LOG(FILENAME) FILENAME##hashcode
宏
的理解:怎么
写
多行的
宏
多行的
宏
只有一行的add
宏
很好
写
,只需要注意优先级就可以解决,但是多行的
宏
呢? 让我们
写
一个简单的swap函数 #define swap(x,y)\ //
写
宏
时不用分号 x = x + y;\ y = x - y;\ x = x - y; //代码结束时,不需要加\ nt main() { int x = 1; int y = 3; Swap(x, y); printf("x = %...
写
宏
注意
今天蛋疼忽然发现看了本c++primer没看到有关于
宏
的说明(也可能是我没注意看) 然后无聊
写
了个简单的试下 #define product(x) x*x #define product2(y) y+y int _tmain(int argc, _TCHAR* argv[]) { char c_wait; int a = 3; int i = 3; i
汇编——
宏
应该
怎么
写
什么是
宏
clojure
宏
写
宏
为什么80%的码农都做不了架构师?>>> ...
如何把鼠标
宏
用c语言
写
出来,鼠标
宏
怎么设置,手把手教你鼠标如何设置
宏
我们知道游戏里,太多的技能和重复的操作让我们的手指跟键盘很辛苦,也不利于取胜,于是就有懒人利用鼠标设置
宏
来把一些快捷技能进行组合,从而达到技能的高效使用了,那么设置鼠标
宏
是什么?下面,小编就来跟大家介绍设置鼠标
宏
的操作流程了。游戏是大家普遍的热爱,对于一个游戏玩家来说,如何高超的操作技能是玩家所追求的,而用户为了得到极致的游戏体验,很多游戏玩家问如何设置
宏
。我们知道鼠标有很多种,有带侧键的,也有不...
C语言
70,040
社区成员
243,237
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章