C中指针在64位操作系统下为什么是4而不是8

发布于:2024-11-29 ⋅ 阅读:(18) ⋅ 点赞:(0)

好久没写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"
}