24

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?

Baruch
  • 20,590
  • 28
  • 126
  • 201

2 Answers2

24

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.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • `but usually there is a strong resistance of C committee to include new features in C` This is an interesting point. Do you have any examples of other features that seem to have not made the cut because of this? Why would this be true for `C`, more than, say, `C++`, which got quite a lot of new features in `C++11`? Or why would this be true at all? Why resist useful additions? – Baruch Jul 20 '14 at 12:20
  • 6
    @baruch There are two things that come to my mind: Dennis Ritchie saying on c99 *"the committee has signaled that much of their time was spent in resisting feature-suggestions"* and in the C99 Rationale document, the Committee says that in the underlying principles upon which C is based, among others, there is this phrase: *"Keep the language small and simple"* – ouah Jul 20 '14 at 12:25
-4

/// 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;
}
shyed2001
  • 35
  • 6
  • 1
    If you intend to printf a wall of text using raw string literals, it's quite pointless to split this printing into multiple calls to `printf`, not even using the advantages of raw literals — like e.g. raw newlines. – Ruslan Aug 03 '21 at 13:21
  • 1
    and bunch of useless includes. `stdio.h` header alone is enough for `printf` – Blanket Fox May 01 '22 at 04:19