Respected sir, I went through the compiler flags and mistake was on my side using the 'w' suppressor flag to remove the warnings without knowing it.Thanks for the docs and reply. By unicode I meant there is a question mark inside a diagonal.(unicode error symbol) Sir this is perspective with the third print that is "cc"+foobar() where I get zR for gcc (9.3.0) and unicode for g++-10.1. I got your point regarding the garbage value and to throw a warning is better than to get such an unwanted output. I thought there would be a specific reason why it had come because in const char *a ="aa"+'operator/number' i.e when I add some character with some change it gives blank space for numbers and operators, where as for addition of 'a' in *a= "aa"+'a' it give 4 times the unicode symbol but for *c="cc" +'c' and *b="bb"+'b' gives a space as output.Yes it has been quite unpredictable and undefined behaviour. So has the request of warning been granted in the upcoming gcc version!? Thanks and regards, Krishna Narayanan. On Fri, Feb 4, 2022 at 2:18 AM Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote: > On Thu, 3 Feb 2022 at 18:46, Krishna Narayanan via Gcc-help > <gcc-help@xxxxxxxxxxx> wrote: > > > > Respected Sir/Madam, > > I have been working on an issue (bug 62181) [C/C++] Expected new warning: > > "adding 'char' to a string does not append to the string" > > [-Wstring-plus-int].This is asking for a warning being added to gcc for > > such a case.Not using concat and indexing which were mentioned earlier > as a > > solution to the warning I tried the example given in > https://godbolt.org/ > > and was trying different permutations of addresses and pointers in clang > > and gcc (trunk), I am not sure but I tried '-w' in compiler flags and it > > worked fine for both clang and gcc ,it did not show any warning.I am not > > sure what exactly did the flag do but the warning arises in other > > optimizations. > > I had a doubt regarding the output of a slightly modified code in which I > > have taken a character instead of int , > > #include <stdio.h> > > char ch ='o'; > > char bar() { > > return 1; > > } > > int foobar() { > > return ch; } > > int main() > > { const char* a = "aa"; > > const char *b = "bb" + bar(); > > const char *c = "cc" + foobar(); > > printf("%s, %s, %s", a, b, c); > > return 0 ; > > } > > In the output I get zR when I did it with gcc and get unicode when done > > with g++10.1 .I did not understand how does this output arise.Can you > > please help me out with this? > > What do you mean you get "unicode"? > > "bb" + bar() is equivalent to "bb" + (int)bar() > which is equivalent to "bb" + 1 > > "cc" + foobar() is equivalent to "cc" + (int)'o' > which has undefined behaviour, because it produces a pointer that is > outside the array of three chars "cc\0". > It will print whatever happens to be in memory approximately 100 bytes > after the "cc" string literal. That is random garbage of some kind. > > The precise behaviour you get from this undefined behaviour is not > important, the point is that it's undefined behaviour, and that's why > a warning would be useful. >