Compiling String Literals

Why can two string literals separated by a space, a tab, or "\ n" be compiled without errors?

int main()
{
   char * a = "aaaa"  "bbbb";
} 

"aaaa" is char * "bbbb" - this is char *

There is no special concatenation rule for processing two string literals. And, obviously, the following code gives an error at compile time:

#include <iostream>
int main()
{
   char * a = "aaaa";
   char * b = "bbbb";
   std::cout << a b;
}

Is this concatenation common to all compilers? Where is the zero termination of "aaaa"? Is "aaaabbbb" a contiguous RAM block?

+4
source share
5 answers

, , 6:

.

, . , .

.

, , .

+9

char * a = "aaaa"  "bbbb";

- .

,

char * a = "aaaabbbb";

"aaaabbbb"

+5

C ( ++). (.. a b).

, ++ 14 ( N3797), Β§ 2.14.5:

6 (2.2) . , . -, , . UTF-8 - , . , .

+4

C ++ . :

"Some text..." "and more text"

:

"Some text...and more text"

:

C 1969-1972 , - 80- . 80 , Teletype ASR-33. , 80 . Fortran Cobol , , , , .

( ) , , , ASCII 80 . C .

, ? . , . , , C .

.

+3

, , 6 ( ). "Hello," " world!" () "Hello, world!". ( ), ( ).

()

+2

Source: https://habr.com/ru/post/1653655/


All Articles