Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C support raw string literals?

Tags:

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?

like image 916
Baruch Avatar asked Jul 20 '14 11:07

Baruch


People also ask

What is a raw string in C?

A rawstring is a string literal (prefixed with an r) in which the normal escaping rules have been suspended so that everything is a literal.

Is string literal in C?

A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string.

Can string literal be modified in C?

C Language Undefined behavior Modify string literalAttempting to modify the string literal has undefined behavior. However, modifying a mutable array of char directly, or through a pointer is naturally not undefined behavior, even if its initializer is a literal string.

What is type of C string literal?

In C the type of a string literal is a char[]. In C++, an ordinary string literal has type 'array of n const char'. For example, The type of the string literal "Hello" is "array of 6 const char".


1 Answers

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 C committee to include new features in C.

and if any compilers support it?

I just tested it and it is apparently supported with recent gcc versions as a GNU extension (compile with -std=gnu99 or -std=gnu11).

For example:

printf(R"(hello\nworld\n)");

compiles and gives the expected behavior.

like image 111
ouah Avatar answered Sep 28 '22 04:09

ouah