string-literals

Does C support raw string literals?

烂漫一生 提交于 2019-11-30 22:53:17
问题 C++11 added support for raw string literals, such as: R"foo(A " weird \" string)foo" Does C have such a thing? If so, in what version of the standard? C11? If not, does anyone know if it is being planed and if any compilers support it? 回答1: Does C have such a thing? If so, in what version of the standard? C11? C (C90, C99, C11) does not support this feature or any other similar feature. If not, does anyone know if it is being planed I have no idea, but usually there is a strong resistance of

MySQL CHAR() Function and UTF8 Output?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 21:45:57
+--------------------------+--------------------------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.1.41-osx10.5-x86_64/share/charsets/ | +--------------------------+--------------------------------------------------------+

C standard : Character set and string encoding specification

帅比萌擦擦* 提交于 2019-11-30 17:51:43
I found the C standard (C99 and C11) vague with respect to character/string code positions and encoding rules: Firstly the standard defines the source character set and the execution character set . Essentially it provides a set of glyphs, but does not associate any numerical values with them - So what is the default character set? I'm not asking about encoding here but just the glyph/repertoire to numeric/code point mapping. It does define universal character names as ISO/IEC 10646, but does it say that this is the default charset? As an extension to the above - I couldn't find anything which

MySQL CHAR() Function and UTF8 Output?

a 夏天 提交于 2019-11-30 17:35:26
问题 +--------------------------+--------------------------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.1.41-osx10.5-x86_64

Some const char * are unavailable at compile time?

早过忘川 提交于 2019-11-30 17:11:43
Let's suppose we have a template function with non-type parameter of const char * like this: template <const char * MESSAGE> void print() { std::cout << MESSAGE << '\n'; } Using this template wouldn't be a problem as log as the MESSAGE can be deduced at compile-time, so the following uses are legal: namespace { char namespace_message[] = "Anonymous Namespace Message"; constexpr char namespace_constexpr_message[] = "Anonymous Namespace Constexpr Message"; } char message[] = "Message"; constexpr char constexpr_message[] = "Constexpr Message"; int main() { print<namespace_message>(); print

Include )" in raw string literal without terminating said literal

老子叫甜甜 提交于 2019-11-30 11:45:55
问题 The two characters )" terminate the raw string literal in the example below. The sequence )" could appear in my text at some point, and I want the string to continue even if this sequence is found within it. R"( Some Text)" )"; // ^^ How can I include the sequence )" within the string literal without terminating it? 回答1: Raw string literals let you specify an almost arbitrary* delimiter: //choose ### as the delimiter so only )###" ends the string R"###( Some Text)" )###"; *The exact rules are

shared c constants in a header

☆樱花仙子☆ 提交于 2019-11-30 11:10:51
I want to share certain C string constants across multiple c files. The constants span multiple lines for readability: const char *QUERY = "SELECT a,b,c " "FROM table..."; Doing above gives redefinition error for QUERY. I don't want to use macro as backspace '\' will be required after every line. I could define these in separate c file and extern the variables in h file but I feel lazy to do that. Is there any other way to achieve this in C? In some .c file, write what you've written. In the appropriate .h file, write extern const char* QUERY; //just declaration Include the .h file wherever

Bus error troubleshooting

别等时光非礼了梦想. 提交于 2019-11-30 09:17:39
I am trying reverse a string. This is the code I tried: #include<stdio.h> #include<string.h> int main(){ char *c="I am a good boy"; printf("\n The input string is : %s\n",c); printf("\n The length of the string is : %d\n",strlen(c)); int i,j; char temp; int len=strlen(c); for(i=0,j=len-1;i<=j;i++,j--) { temp=c[i]; c[i]=c[j]; c[j]=temp; //printf("%c\t%c\n",*(c+i),*(c+(len-i-1))); } printf("\n reversed string is : %s\n\n",c); } The code outputs a Bus error : 10 . But if I rewrite the same code as: int main(void) { char *str; str="I am a good boy"; int i,j; char temp; int len=strlen(str); char

MySQL unicode literals

对着背影说爱祢 提交于 2019-11-30 08:32:05
I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? dkamins See: http://bugs.mysql.com/bug.php?id=10199 (Bug #10199: "Allow Unicode escape sequence for string literals.") This request has been "Open" since 2005. More details in Worklog Task #3529: Unicode Escape Sequences . From https://web.archive.org/web/20091117221116/http://eng.kaching.com/2009/10/mysql-unicode-escape-sequences.html though, you can see the following example, which

What is the result of decltype(“Hello”)?

旧街凉风 提交于 2019-11-30 07:52:24
I'm getting unexpected results from all compilers on which I tried the following (GCC 4.7.2, GCC 4.8.0 beta, ICC 13.0.1, Clang 3.2, VC10): #include <type_traits> int main() { // This will fire static_assert( std::is_same<decltype("Hello"), char const[6]>::value, "Error!" ); } I would have expected the compile-time assertion above not to fire, but it does. After all, this one does not (as expected): #include <type_traits> int main() { char const hello[6] = "Hello"; // This will not fire static_assert( std::is_same<decltype(hello), char const[6]>::value, "Error!" ); } So what is the result of