Baruch
Baruch

Reputation: 21548

Does C support raw string literals?

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?

Upvotes: 26

Views: 17786

Answers (2)

shyed2001
shyed2001

Reputation: 7

/// My experience. Using Code blocks, GCC MinGW.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <windows.h>
///#include <threads.h>
#include <conio.h>
/// #include <dos.h>
#include <direct.h>

int main(void)

{
  printf(R"(.C with a Capital C file format does not support raw string )");
  printf("\n");
  printf(R"(.c with a small c file format does support raw string )");
  printf("\n");
  printf(R"( Raw string did not support \n new line )");
  printf("\n");

  printf(
      R"(More reading material at - https: // en.wikipedia.org/wiki/String_literal#Raw_strings;)");
  printf("\n");
  printf(
      R"(More reading material at - https: // en.wikipedia.org/wiki/String_literal;)");
  printf("\n");
  printf(
      R"(More reading material at - https://stackoverflow.com/questions/24850244/does-c-support-raw-string-literals;)");
  printf("\n");
  printf(
      R"(More reading material at - https: // learn.microsoft.com/en-us/cpp/c-language/c-string-literals?view=vs-2019)");
  printf("\n");
  printf(
      R"(More reading material at-https: // learn.microsoft.com/en-us/cpp/c-language/string-literal-concatenation?view=vs-2019)");
  printf("\n");
  /// Raw string.

    printf(R"(More reading material at - https://www.geeksforgeeks.org/const-qualifier-in-c/;)");
  printf("\n");
  
  
  return 0;
}

Upvotes: -7

ouah
ouah

Reputation: 145919

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.

Upvotes: 27

Related Questions