The best way to answer your question is to rewrite it as a Program that compiles identically when using a "C" or "C++" Compiler, I will assume you are using GCC but other (correctly written) Compiler Toolchains should provide similar results.
First I will address each point you posed then I will give a Program that provides the answer (and Proof).
- As far as I can tell, before C++11, string literals were handled in almost exactly the same way between C and C++.
They still can be handled the same way using various Command Line Parameters, in this example I will use "-fpermissive" (a Cheat). You are better off finding out why you are getting Warnings and writing NEW Code to avoid ANY Warning; only use CLP 'cheats' to compile OLD Code.
Write new Code correctly (no cheats and no Warnings, that there be no Errors goes without saying).
- Now, I acknowledge that there are differences between C and C++ in the handling of wide string literals.
There does not have to be (many differences) since you can cheat most or all of them away depending on the circumstances. Cheating is wrong, learn to program correctly and follow modern Standards not the mistakes (or awkwardness) of the past. Things are done a certain way to be helpful both to you, and to the Compiler in some cases (remember YOU are not the only one who 'sees' your Code).
In this case the Compiler wants enough space allocated to terminate the String with a '0' (zero byte). That permits the use of a print (and some other) Function without specifying the length of the String.
IF you are simply trying to compile an existing Program you obtained from somewhere and do not want to re-write it, you simply want to compile it and run it, then use the cheats (if you must) to get past the Warnings and force the compilation to an executable.
- The rest of what you wrote ...
No.
.
See this example Program. I slightly modified your question to make it into a Program. The result of compiling this Program with a "C" or C++" Compiler is identical.
Copy-and-Paste the example Program text below to a File called "test.c", then follow the instructions at the start. Simply 'cat' the File so you can backscroll it (and see it) without opening a Text Editor, then Copy-and-Paste each Line beginning with the Compiler Commands (the next three).
Note, that as pointed out in the Comments, that running this Line "g++ -S -o test_c++.s test.c" produces an Error (using a modern g++ Compiler) since the container is not long enough to hold the String.
You should be able to read this Program and not actually need to compile it to see the Answer but it will compile and produce the Output for you to examine should you desire to do so.
As you can see the Varable "str1" is not long enough to hold the String when it is null terminated, that produces an Error on a modern (and correctly written) g++ Compiler.
/* Answer for: http://stackoverflow.com/questions/23145793/string-literal-differences-between-c-and-c
*
* cat test.c
* gcc -S -o test_c.s test.c
* g++ -S -o test_c++.s test.c
* g++ -S -fpermissive -o test_c++.s test.c
*
*/
char str1[3] = "1ab";
char str2[4] = "2ab";
char str3[] = "3ab";
main(){return 0;}
/* Comment: Executing "g++ -S -o test_c++.s test.c" produces this Error:
*
* test.c:10:16: error: initializer-string for array of chars is too long [-fpermissive]
* char str1[3] = "1ab";
* ^
*
*/
/* Resulting Assembly Language Output */
/* .file "test.c"
* .globl _str1
* .data
* _str1:
* .ascii "1ab"
* .globl _str2
* _str2:
* .ascii "2ab\0"
* .globl _str3
* _str3:
* .ascii "3ab\0"
* .def ___main; .scl 2; .type 32; .endef
* .text
* .globl _main
* .def _main; .scl 2; .type 32; .endef
* _main:
* LFB0:
* .cfi_startproc
* pushl %ebp
* .cfi_def_cfa_offset 8
* .cfi_offset 5, -8
* movl %esp, %ebp
* .cfi_def_cfa_register 5
* andl $-16, %esp
* call ___main
* movl $0, %eax
* leave
* .cfi_restore 5
* .cfi_def_cfa 4, 4
* ret
* .cfi_endproc
* LFE0:
* .ident "GCC: (GNU) 4.8.2"
*
*/