好久没写C了,今天用VScode想写个Demo,翻了下指针资料,想打印下指针大小,发现是4,但是理论上64位系统不应该是8么?
结论就是我编的是32位程序,编译器按照32位编译的。
用vscode的C++ 插件编译运行:
用新编译器编译64位程序:
问题答案:
https://learn.microsoft.com/en-us/answers/questions/81012/pointer-size-in-64-bit-operating-system
附:
launch.json
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(mingW64) 启动","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\Applications\\mingw_64\\mingw64\\bin\\gdb.exe","setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true},{"description": "将反汇编风格设置为 Intel","text": "-gdb-set disassembly-flavor intel","ignoreFailures": true}],"preLaunchTask": "mingW64"}]
}
task.json
{"tasks": [{"label": "mingW64","type": "shell","command": "D:\\Applications\\mingw_64\\mingw64\\bin\\gcc.exe","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe","-fexec-charset=GBK",],"options": {"cwd": "${workspaceFolder}"//当前工作目录(路径)。},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},}],"version": "2.0.0"
}