我正在尝试运行程序,在Ubuntu 12.10上使用boost :: filesystem的示例代码,但它不想构建.
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
using namespace std;
void fun(const string& dirPath);
int main()
{
fun("/home");
return 0;
}
void fun(const string& dirPath)
{
path p (dirPath);
if (exists(p))
{
if (is_regular_file(p))
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p))
cout << p << "is a directory\n";
else
cout << p << "exists, but is neither a regular file nor a directory\n";
}
else
cout << p …Run Code Online (Sandbox Code Playgroud) 我得到了结构:
typedef struct
{
int a;
int b;
int c;
}Z;
Run Code Online (Sandbox Code Playgroud)
码:
int main()
{
Z *a = (Z*)malloc(sizeof(Z)*8);
Z *b = (Z*)malloc(sizeof(Z)*8);
printf("%lu\n", sizeof(Z));
printf("%p %p\n", b, a);
printf("%lu\n", b - a);
}
Run Code Online (Sandbox Code Playgroud)
输出:
12
0x89a080 0x89a010
12297829382473034420
Run Code Online (Sandbox Code Playgroud)
为什么最后一行的价值如此之大?实际地址差异是0x70(16个字节的堆分配头加上数组a的12*8个字节的元素),所以从指针的算术我期望值0x70/12 = 9.(3)或9转换为整数.我知道减去指针不指向相同的数组,但我期望更合理的结果,这将让我知道内存映射的样子.它是在64b Ubuntu和gcc 4.8.2上编译的.
部件:
.file "aa.c"
.section .rodata
.LC0:
.string "%lu\n"
.LC1:
.string "%p %p\n"
.text
.globl main
.type main, @function
main:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp …Run Code Online (Sandbox Code Playgroud)