__FILE__的缩写形式 [英] Short form of __FILE__

查看:81
本文介绍了__FILE__的缩写形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


用于调试目的,我喜欢预编译器宏


__FILE __,__功能___,__LINE__


我一直在想是否有__FILE__的简短形式

只提供没有路径的文件名。


我是在Debian中使用gcc不稳定:


gcc(GCC)4.0.3 20060128(预发布)(Debian 4.0.2-8)

阅读信息gcc上的页面没有透露我正在寻找的内容

for。因此我的问题....


wbr,

Lukas

-

Lukas Ruf < HTTP://www.lpr.ch> | Ad Personam

rbacs< http://wiki.lpr.ch> |餐厅,酒吧和俱乐部

Raw IP< http://www.rawip.org> |低级网络编程

风格< http://email.rawip.org> |如何写电子邮件

解决方案



" Lukas Ruf" < ru*@rawip.org>在留言中写道

news:sl **************** @ pc-4082.ethz.ch ...

亲爱的所有,

出于调试目的,我喜欢预编译宏

__FILE __,__功能___,_ _ _ _ _ _ _ _ _ _
我一直想知道是否有__FILE__的缩写形式
只提供没有路径的文件名。

我使用的是Debian不稳定的gcc:

gcc(GCC)4.0.3 20060128 (预发布)(Debian 4.0.2-8)

阅读gcc上的信息页面并未透露我正在寻找的内容。因此我的问题....



__FILE__包含给编译器的任何路径。


考虑一个简单的''test.c' '...


#include< stdio.h>

int main(void){puts(__ FILE__);返回0;}


如果你像这样编译test.c:gcc -E test.c


你会看到__FILE__是 test.c"。


如果你像这样编译gcc -E ./test.c


你会看到__FILE__是 ./test.c" ;.


-

==============

*不是学究者*

==============


> pemo [Mon,2006年2月6日15:44:42 -0000]:



感谢您的信息!

Lukas Ruf < ru*@rawip.org>在消息中写道
新闻:sl **************** @ pc-4082.ethz.ch ...

亲爱的所有人,

出于调试目的,我喜欢预编译宏

__FILE __,__功能___,_ _ _ _ _ _ _ _ _ _

我一直想知道是否有__FILE__的简短形式那个
只提供没有路径的文件名。

我使用的是Debian不稳定的gcc:

gcc(GCC)4.0.3 20060128(预发布)( Debian 4.0.2-8)

阅读gcc上的信息页面并没有透露我正在寻找的内容。因此我的问题....



__FILE__包含给编译器的任何路径。

考虑一个简单的''test.c''...

#include< stdio.h>
int main(void){puts(__ FILE__);返回0;}

如果你像这样编译test.c:gcc -E test.c

你会看到__FILE__是test.c。

如果你像这样编译gcc -E ./test.c

你会看到__FILE__是./ test.c。




wbr,

Lukas

-

Lukas Ruf< http://www.lpr.ch> | Ad Personam

rbacs< http://wiki.lpr.ch> |餐厅,酒吧和俱乐部

Raw IP< http://www.rawip.org> |低级网络编程

风格< http://email.rawip.org> |如何撰写电子邮件


2006-02-06 10:29:14 -0500,Lukas Ruf< ru*@rawip.org>说:

亲爱的,

出于调试目的,我喜欢预编译宏
__ FILE __,__ FUNCTION __,_ _ _ _ _ _ br />
我一直想知道是否有一个简短形式的__FILE__
只提供没有路径的文件名。


否。无论__FILE__扩展到什么,都取决于您的编译器。一些

编译器可能会提供更改此选项的选项,或者可能提供其他

宏作为扩展名。根据您对此信息的需求,

您可以在运行时解析由__FILE__给出的字符串。


我在Debian unstable中使用gcc :

gcc(GCC)4.0.3 20060128(预发布)(Debian 4.0.2-8)




< OT>

使用GCC,它扩展到

命令行传递给编译器的任何内容,因此给出以下文件:

/ * begin test。 c * /

#include< stdio.h>


int main()

{

printf(" \" __ FILE__ \"扩展为\"%s \" \ n",__ FILE__);

返回0;

}

/ * end test.c * /

在我的机器上:

[littleclark2:〜] clarkcox%gcc test .c&& ./a.out

" __ FILE __"扩展为test.c

[littleclark2:〜] clarkcox%gcc ./test.c& amp;& ./a.out

" __ FILE __"扩展为./ test.c

[littleclark2:〜] clarkcox%gcc~ / test.c&& ./a.out

" __ FILE __"扩展为/Users/clarkcox/test.c"

[littleclark2:〜] clarkcox%gcc ../clarkcox/test.c& amp;& ./a.out

" __ FILE __"扩展为../ clarkcox / test.c

< / OT>

-

Clark S. Cox,III
cl*******@gmail.com


Dear all,

for debugging purposes, I like the pre-compiler macros

__FILE__, __FUNCTION__, __LINE__

I have been wondering if there is a short form of __FILE__ that
provides only the filename without path.

I am using gcc as available in Debian unstable:

gcc (GCC) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)
Reading the info pages on gcc has not revealed what I am looking
for. Hence my question....

wbr,
Lukas
--
Lukas Ruf <http://www.lpr.ch> | Ad Personam
rbacs <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP <http://www.rawip.org> | Low Level Network Programming
Style <http://email.rawip.org> | How to write emails

解决方案


"Lukas Ruf" <ru*@rawip.org> wrote in message
news:sl****************@pc-4082.ethz.ch...

Dear all,

for debugging purposes, I like the pre-compiler macros

__FILE__, __FUNCTION__, __LINE__

I have been wondering if there is a short form of __FILE__ that
provides only the filename without path.

I am using gcc as available in Debian unstable:

gcc (GCC) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)
Reading the info pages on gcc has not revealed what I am looking
for. Hence my question....


__FILE__ contains whatever path is given to the compiler.

consider a simple ''test.c'' ...

#include <stdio.h>
int main(void){puts(__FILE__); return 0;}

If you compile test.c like this: gcc -E test.c

You will see __FILE__ is "test.c".

If you compile it like this gcc -E ./test.c

You will see __FILE__ is "./test.c".

--
==============
*Not a pedant*
==============


> pemo [Mon, 6 Feb 2006 15:44:42 -0000]:


thanks for the info!

"Lukas Ruf" <ru*@rawip.org> wrote in message
news:sl****************@pc-4082.ethz.ch...

Dear all,

for debugging purposes, I like the pre-compiler macros

__FILE__, __FUNCTION__, __LINE__

I have been wondering if there is a short form of __FILE__ that
provides only the filename without path.

I am using gcc as available in Debian unstable:

gcc (GCC) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)
Reading the info pages on gcc has not revealed what I am looking
for. Hence my question....


__FILE__ contains whatever path is given to the compiler.

consider a simple ''test.c'' ...

#include <stdio.h>
int main(void){puts(__FILE__); return 0;}

If you compile test.c like this: gcc -E test.c

You will see __FILE__ is "test.c".

If you compile it like this gcc -E ./test.c

You will see __FILE__ is "./test.c".



wbr,
Lukas
--
Lukas Ruf <http://www.lpr.ch> | Ad Personam
rbacs <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP <http://www.rawip.org> | Low Level Network Programming
Style <http://email.rawip.org> | How to write emails


On 2006-02-06 10:29:14 -0500, Lukas Ruf <ru*@rawip.org> said:

Dear all,

for debugging purposes, I like the pre-compiler macros

__FILE__, __FUNCTION__, __LINE__

I have been wondering if there is a short form of __FILE__ that
provides only the filename without path.
No. Whatever __FILE__ expands to is really up to your compiler. Some
compilers may provide options to change this, or may provide other
macros as an extension. Depending on your need for this information,
you could just parse the string given you by __FILE__ at runtime.


I am using gcc as available in Debian unstable:

gcc (GCC) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)



<OT>
With GCC, it expands to whatever was passed to the compiler on the
command line, so given the following file:
/* begin test.c */
#include <stdio.h>

int main()
{
printf("\"__FILE__\" expands to \"%s\"\n", __FILE__);
return 0;
}
/* end test.c */
On my machine:
[littleclark2:~] clarkcox% gcc test.c && ./a.out
"__FILE__" expands to "test.c"
[littleclark2:~] clarkcox% gcc ./test.c && ./a.out
"__FILE__" expands to "./test.c"
[littleclark2:~] clarkcox% gcc ~/test.c && ./a.out
"__FILE__" expands to "/Users/clarkcox/test.c"
[littleclark2:~] clarkcox% gcc ../clarkcox/test.c && ./a.out
"__FILE__" expands to "../clarkcox/test.c"
</OT>
--
Clark S. Cox, III
cl*******@gmail.com


这篇关于__FILE__的缩写形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆