You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++中typeid(var).name()输出的PKc具体含义是什么?

Understanding the PKc Output from typeid(typeid(check).name()).name()

Great question! Let’s break down exactly what’s going on here and decode that mysterious PKc output you’re seeing.

First, let’s clarify the chain of calls

  • When you run typeid(check).name(), you’re getting GCC’s mangled shorthand for the type of check: 'c' for char, 'd' for double, etc.
  • The critical detail you might have missed: std::type_info::name() always returns a const char*, no matter what type check is. This is a fixed part of the C++ standard.

Decoding PKc

GCC uses a name mangling system to pack complex type names into short strings. Let’s unpack PKc piece by piece:

  • P: Abbreviation for "pointer"
  • K: Abbreviation for "const" (it comes from the German word Konstant, which is why it’s not C)
  • c: Abbreviation for char

Put it all together, PKc is GCC’s mangled way of writing const char* — which is exactly the type of the value returned by typeid(check).name(). That’s why changing check’s type doesn’t change this output: you’re always asking for the type of the same const char* pointer.

Verify with demangled output

If you want to see a human-readable version instead of the mangled string, you can use GCC’s built-in demangling function. Here’s a quick example:

#include <bits/stdc++.h>
#include <cxxabi.h>

int main() {
    double check = 69.666;
    const char* mangled_type = typeid(typeid(check).name()).name();
    
    int demangle_status;
    char* demangled = abi::__cxa_demangle(mangled_type, nullptr, nullptr, &demangle_status);
    
    if (demangle_status == 0) {
        std::cout << "Demangled type: " << demangled << "\n";
        free(demangled); // Clean up the allocated memory
    } else {
        std::cout << "Couldn't demangle the type name\n";
    }
    
    return 0;
}

Running this will output:

Demangled type: char const*

Which confirms our explanation perfectly.

内容的提问来源于stack exchange,提问作者pkdyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:00:51