IP 属地广东
黄兢成iOS / Mac / C++ 开发者
他的动态
C++ 标准不支持 flexible array。-Wpedantic 编译,clang 会有警告。C++ 中可这样写: #include <stdio.h> #include <stdlib.h> #include <string.h> struct Test final { int a; double b; char *str() { return (char *)(this + 1); } }; int main(int argc, const char *argv[]) { Test *pa = (Test *)malloc(sizeof(Test) + 12); strcpy(pa->str(), "hello world"); printf("%s ", pa->str()); return 0; }