我注意到字符串文字在内存中的地址与其他常量和变量(Linux OS)的地址非常不同:它们有许多前导零(不打印).
例:
const char *h = "Hi";
int i = 1;
printf ("%p\n", (void *) h);
printf ("%p\n", (void *) &i);
Run Code Online (Sandbox Code Playgroud)
输出:
0x400634
0x7fffc1ef1a4c
Run Code Online (Sandbox Code Playgroud)
我知道它们存储在.rodata可执行文件的一部分中.操作系统之后是否有一种特殊的方式处理它,所以文字最终会出现在一个特殊的内存区域(带有前导零)?这个内存位置有什么优点还是有什么特别之处呢?
这是我的一部分 CMakeLists.txt
set (VTK_DIR "/usr/include/vtk-5.8")
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
IF(VTK_FOUND)
message("found VTK. Version:" ${VTK_VERSION}. VTK_DIR: ${VTK_DIR})
ELSE(VTK_FOUND)
MESSAGE(FATAL_ERROR
"Cannot build the executable without VTK. Please set the
VTK_DIR")
ENDIF(VTK_FOUND)
Run Code Online (Sandbox Code Playgroud)
cmake . 告诉我:
发现VTK。版本:6.0.0.VTK_DIR:/usr/local/lib/cmake/vtk-6.0
在命令行中提供 VTK_DIR 也无济于事:
cmake -DVTK_DIR:PATH=/usr/include/vtk-5.8 .
Run Code Online (Sandbox Code Playgroud)
仍然 cmake 寻找/usr/local/lib/cmake/vtk-6.0VTK。
这里有什么问题?