学习随笔

来源:互联网 发布:大数据的安全管理 编辑:程序博客网 时间:2024/05/21 15:05

#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.

1234567891011
// a.h#ifndef INCLUDED_A#define INCLUDED_A#ifndef INCLUDED_BASE#include "base.h"#endif//code#endif 


1234567891011
// b.h#ifndef INCLUDED_B#define INCLUDED_B#ifndef INCLUDED_BASE#include "base.h"#endif//code#endif 


1234567
// 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.

原创粉丝点击