To enable debugging:
1) Goto Project->HelloWorld Properties
2) On the left expand "Configuration Properties"
3) Expand "C/C++"
4) On the left, Select "General"
5) On the right, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
5) On the left, Select "Optimization"
6) On the right, change "Optimization" to "Disabled (/Od)"
7) On the left, expand "Linker"
8) On the left, select "Debugging"
9) On the right, change "Generate Debug Info" to "Yes"
10) Click ok
11) Set your breakpoints
12) Rebuild your application
Also when running your application use Ctrl+F5 to build and run it, this keeps the console window open long enough for you to see your output.
最近读libuv源码,看到了ngx_queue_t,里边用到了offsetof,第一次看到,网上查了一下,原来是获取struct成员内存地址相对于struct地址的偏移量,今儿想到了怎么实现的呢。
struct A {
int i;
char c;
float f;
};
A* a = (A*)0;
size_t offset = (size_t)&(a->c);
printf("%lu\n", offset);
#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER )
一共4步
1. ( (TYPE *)0 ) 将零转型为TYPE类型指针;
2. ((TYPE *)0)->MEMBER 访问结构中的数据成员;
3. &( ( (TYPE *)0 )->MEMBER )取出数据成员的地址;
4.(size_t)(&(((TYPE*)0)->MEMBER))结果转换类型.巧妙之处在于将0转换成(TYPE*),结构以内存空间首地址0作为起始地址,则成员地址自然为偏移地址;
首先,我们要先安装gyp
git clone https://chromium.googlesource.com/external/gyp.git
cd gyp
sudo python setup.py install
这个是make file
gyp mylib.gyp --depth=. -f make --generator-output=./build/makefiles
make -C ./build/makefiles/
这个是scons
gyp mylib.gyp --depth=. -f scons --generator-output=./build/sconsfiles
scons -C ./build/sconsfiles/
这个是xcode
gyp mylib.gyp --depth=. -f xcode --generator-output=./build/xcodefiles
xcodebuild -project ./build/xcodefiles/mylib.xcodeproj
这个是ninja
gyp mylib.gyp --depth=. -f ninja
ninja -v -C out/Release/ -f build.ninja
这个是vs
python gyp/gyp mylib.gyp --depth=. -f msvs -G msvs_version=2010
msbuild mylib.sln
gyp脚本编写,接下来再写。