public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Krishna Narayanan <krishnanarayanan132002@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Doubts regarding the issue (bug 62181)
Date: Fri, 4 Feb 2022 12:13:44 +0000	[thread overview]
Message-ID: <CAH6eHdTL-EqAoZv6_BpBBmfKjGOuOCyWTPLq43NNg4VR=3MkJw@mail.gmail.com> (raw)
In-Reply-To: <CABhGnjteb0nKAUrQfkzYrs4gOJeb079ygY-wCbu4i7eRcFwZ-w@mail.gmail.com>

On Fri, 4 Feb 2022 at 11:36, Krishna Narayanan via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> 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)

That means it's printing garbage characters that can't be processed as
valid UTF-8, so explicitly NOT unicode. Calling that unicode is very
confusing.


> 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.

The nature of undefined behaviour is to be unpredictable.

Compile with -fsanitize=address to get a lot more detail about what
your buggy code is doing. You'll see an explanation of where the
pointer arithmetic goes, and what's in memory there.



>
> So has the request of warning been granted in the upcoming gcc version!?

Do you get any warning when compiling your buggy example with gcc? I don't.

However, when I compile it with clang I get:

oflow.c:10:23: warning: adding 'char' to a string does not append to
the string [-Wstring-plus-int]
const char *b = "bb" + bar();
                ~~~~~^~~~~~~
oflow.c:10:23: note: use array indexing to silence this warning
const char *b = "bb" + bar();
                     ^
                &    [      ]
oflow.c:11:22: warning: adding 'int' to a string does not append to
the string [-Wstring-plus-int]
const char *c = "cc" + foobar();
               ~~~~~^~~~~~~~~~
oflow.c:11:22: note: use array indexing to silence this warning
const char *c = "cc" + foobar();
                    ^
               &    [         ]
2 warnings generated.

  reply	other threads:[~2022-02-04 12:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 18:45 Krishna Narayanan
2022-02-03 20:47 ` Jonathan Wakely
2022-02-04 11:35   ` Krishna Narayanan
2022-02-04 12:13     ` Jonathan Wakely [this message]
2022-02-04 16:24       ` Krishna Narayanan
2022-02-03 20:49 ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH6eHdTL-EqAoZv6_BpBBmfKjGOuOCyWTPLq43NNg4VR=3MkJw@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=krishnanarayanan132002@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).