VC 中输出当前运行的文件和所处的行数以及所在函数名称的方法

通过下面的例子,可以到到 VC 可以在运行过程中输出当前运行的文件和所处的行数以及所在函数名称。如果需要追踪你程序的流程,并且能够获得运行期的Log文件,这将是一个很好的追踪方法

#include “stdafx.h”

void foo()
{
printf(“Run in file %s, line %d Function %s\n”, __FILE__, __LINE__, __FUNCDNAME__);
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
printf(“This is a simple demo to show how to show Filename Line Number and Function Name \n”);
printf(” Powered by www.lab-z.com Z.t \n”);
printf(“Run in file %s, line %d Function %s\n”, __FILE__, __LINE__, __FUNCDNAME__);
foo();
getchar();
return 0;
}

运行结果:

1

注意到其中的文件名给出的是相对路径,可以通过下面的位置设置为完整路径

2

之后的运行结果

Untitled

其中使用的 __FILE__ 和 __LINE__ 是c语言标准中定义的

下面文字来源于 http://topic.okbase.net/200510/2005102110/2170344.html

看ISO14882
6.10.8 Predefined macro names
1 The following macro names148) shall be defined by the implementation:
_ _DATE_ _ The date of translation of the preprocessing translation unit: a character
string literal of the form “Mmm dd yyyy”, where the names of the
months are the same as those generated by the asctime function, and the
first character of dd is a space character if the value is less than 10. If the
date of translation is not available, an implementation-defined valid date
shall be supplied.
_ _FILE_ _ The presumed name of the current source file (a character string literal).149)
_ _LINE_ _ The presumed line number (within the current source file) of the current
source line (an integer constant).149)
_ _STDC_ _ The integer constant 1, intended to indicate a conforming implementation.
_ _STDC_HOSTED_ _ The integer constant 1 if the implementation is a hosted
implementation or the integer constant 0 if it is not.
_ _STDC_VERSION_ _ The integer constant 199901L.150)
_ _TIME_ _ The time of translation of the preprocessing translation unit: a character
string literal of the form “hh:mm:ss” as in the time generated by the
asctime function. If the time of translation is not available, an
implementation-defined valid time shall be supplied.
2 The following macro names are conditionally defined by the implementation:
_ _STDC_IEC_559_ _ The integer constant 1, intended to indicate conformance to the
specifications in annex F (IEC 60559 floating-point arithmetic).
148) See ‘‘future language directions’’ (6.11.9).
149) The presumed source file name and line number can be changed by the #line directive.
150) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
ISO/IEC 9899/AMD1:1995. The intention is that this will remain an integer constant of type long
int that is increased with each revision of this International Standard.
160 Language §6.10.8
©ISO/IEC ISO/IEC 9899:1999 (E)
_ _STDC_IEC_559_COMPLEX_ _ The integer constant 1, intended to indicate
adherence to the specifications in informative annex G (IEC 60559
compatible complex arithmetic).
_ _STDC_ISO_10646_ _ An integer constant of the form yyyymmL (for example,
199712L), intended to indicate that values of type wchar_t are the
coded representations of the characters defined by ISO/IEC 10646, along
with all amendments and technical corrigenda as of the specified year and
month.
3 The values of the predefined macros (except for _ _FILE_ _ and _ _LINE_ _) remain
constant throughout the translation unit.
4 None of these macro names, nor the identifier defined, shall be the subject of a
#define or a #undef preprocessing directive. Any other predefined macro names
shall begin with a leading underscore followed by an uppercase letter or a second
underscore.
5 The implementation shall not predefine the macro _ _cplusplus, nor shall it define it
in any standard header.
Forward references: the asctime function (7.23.3.1), standard headers (7.1.2).

__FUNCDNAME__ 是 VC 自定义的
介绍在 http://msdn.microsoft.com/en-us/library/b0084kay(VS.71).aspx

__FUNCDNAME__ Valid only within a function and returns the decorated name of the enclosing
function (as a string). __FUNCDNAME__ is not expanded if you use the /EP or /P compiler option.

给WordPress加上文章阅读次数功能

安装完WordPress后(WordPress 3.5.1),默认已经有 WP-PostViews 插件,可以直接在“插件”–>;“已安装的插件”中看到。确定这个功能是启用之后,可以在“外观”–>;当前主题的“小工具”中配置“第一小工具区”中 Views。这样就能够在边栏显示阅读数量最多的文章。具体的配置方法在网上都能搜索到,这里不再重复。重点说一下 Twenty Ten 这个主题如何显示每篇文章的阅读数量。非常抱歉的是这个主题和其他网上教程中讲述的都不同,无法找到给出的“主循环”。因此,选择插入在 Single.php 文件中(可以从“仪表盘”–>“外观”–>“编辑”直接选择编辑文件)。注意要加入到下面指定的位置中

之后就是这样的效果了………

参考如下文章:

http://wordpress.org.cn/thread-143947-2-1.html

更新完成

用了一个春节的时间,将原来手工页面编写的网页更换为了 WordPress 界面的。总共花费了大约100多个小时。期间的感悟是:360浏览器真的不好用,不知道为什么家里的电脑强制安装了一个360浏览器,我刚开始也没有在意,用着它就开始了WP之旅,不成想几乎上传几次附件之后就要崩溃一次,整个浏览器都没有反应的。后来的某一天,去给一个朋友检修电脑,她也提到浏览器不正常的问题而正好也是360浏览器,始悟一定是它捣鬼的……果真更新之后正常多了。不太清楚,360使用的是IE内核,但是为什么把浏览器搞的如此之不好用?

另外一个感悟是,Wordpress的安装和使用比想象中的简单多了,功能也是异乎寻常的强大。现在可以方便的显示阅读最多的文章,也可以方便的让别人订阅我的RSS。看起来引入新技术,引入新方法能够提高效率才是最顺应潮流的做法。

最后放上两张很久之前CPascal的网站截图,聊作纪念。