string-literals

typeid(“”) != typeid(const char*)

狂风中的少年 提交于 2021-01-26 19:25:42
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

typeid(“”) != typeid(const char*)

笑着哭i 提交于 2021-01-26 19:25:18
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

How do you safely declare a 16-bit string literal in C?

我只是一个虾纸丫 提交于 2020-08-07 03:40:37
问题 I'm aware that there is already a standard method by prefixing with L : wchar_t *test_literal = L"Test"; The problem is that wchar_t is not guaranteed to be 16-bits, but for my project, I need a 16-bit wchar_t . I'd also like to avoid the requirement of passing -fshort-wchar . So, is there any prefix for C (not C++) that will allow me to declare a UTF-16 string literal? 回答1: So, is there any prefix for C (not C++) that will allow me to declare a UTF-16 string literal? Almost, but not quite.

relocation R_X86_64_8 against undefined symbol `ELF' can not be used when making a PIE object

冷暖自知 提交于 2020-07-09 11:55:27
问题 Having this in gas: .text .globl main main: xor %eax, %eax lea str(%rip), %rdi call printf call exit str: .byte 0x7F, "ELF", 1,1,1,0 I thought the .byte directive could be concatenate as in nasm db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident source : http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html 回答1: In GAS syntax, "ELF" is a symbol reference to the symbol name ELF , not a multi-char string. In the context of .byte directive, it's only looking for a number, not a possible string. And