学习随笔

#define is a pre-preprocessor directive, executed before the compiler sees the code, and therefore is not a language element of C itself.

Generally enums are preferred as they are type-safe and more easily discoverable.Defines are harder to locate and can have complex behavior, for example one piece of code can redefine a#define made by another(编译器warning,而enum直接产生error). This can be hard to track down.

Since enums are available to the compiler, symbol information on them can be passed through to the debugger, making debugging easier.


2012/3/23

Syntax

DWORD WINAPI GetTickCount(void);

Parameters

This function has no parameters.

Return value

The return value is the number of milliseconds that have elapsed since the system was started.

Remarks

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

绝对路径:是从盘符开始的路径,形如
C:\windows\system32\cmd.exe
相对路径:是从当前路径开始的路径,假如当前路径为C:\windows
要描述上述路径,只需输入
system32\cmd.exe
实际上,严格的相对路径写法应为
.\system32\cmd.exe
其中,.表示当前路径,在通道情况下可以省略,只有在特殊的情况下不能省略。
假如当前路径为c:\program files
要调用上述命令,则需要输入
..\windows\system32\cmd.exe
其中,..为父目录。
当前路径如果为c:\program files\common files
则需要输入
..\..\windows\system32\cmd.exe

另外,还有一种不包含盘符的特殊绝对路径,形如
\windows\system32\cmd.exe
无论当前路径是什么,会自动地从当前盘的根目录开始查找指定的程序。


在C语言中,除了 sizeof(数组表达式) 和 &数组表达式 之外,都发生这一转换.也就是说,除了用 sizeof(),和 &外 ,任何操作都不能操作一个数组本身,而是操作它的元素的指针来间接地这个数组. 如int a[3];int b[3] = a;//用数组a 来初始化数组b,这是错的,因为作为 = 操作的操作数时,发生上述转换,a被转换成int*指针.

   由于编译器每次都需要打开头文件才能判定是否有重复定义,因此在编译大型项目时,ifndef会使得编译时间相对较长,因此一些编译器逐渐开始支持#pragma once的方式。

"external include guards"/"redundant include guards"

Not only should you use a unique and predictable (internal) include guard but you should also consider using (external) include guards around each preprocessor include directive in header files.

The following is a small example, both a.h and b.h include base.h but preprocessor will have information to not even visit base.h a second time. It makes little difference on a small project, but a large difference on big ones.

1
2
3
4
5
6
7
8
9
10
11
// a.h
#ifndef INCLUDED_A
#define INCLUDED_A

#ifndef INCLUDED_BASE
#include "base.h"
#endif

//code

#endif 


1
2
3
4
5
6
7
8
9
10
11
// b.h
#ifndef INCLUDED_B
#define INCLUDED_B

#ifndef INCLUDED_BASE
#include "base.h"
#endif

//code

#endif 


1
2
3
4
5
6
7
// base.h
#ifndef INCLUDED_BASE
#define INCLUDED_BASE

//code

#endif 
When the preprocessor is doing it's business and finds an #include, it goes off loads the included file and reads the first line. It finds the guard definition and has a look to see if it is already defined. If it is it still has to process the file until it finds the corresponding #endif and then carry on processing the file to the end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值