cstring-literals

What does it do to juxtapose string literals next to each other?


fd1 = open("/dev/test_kft" "1",00);

What does "/dev/test_kft" "1" mean?


Solution

  • The explicit form in C is this:

    char part1[] = "/dev/test_kft";
    char part2[] = "1";
    char path[strlen(part1) + strlen(part2) + 1];
    strcpy(path, part1);
    strcat(path, part2);
    

    This still does not replicate the fact that the "implicit" concatenation form is place in the rodata segment. In the example I've given, it'll be on the stack. You could put it on the heap with malloc. The implicit version is done at compile time, and preferred if possible.