public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ponnuvel Palaniyappan <pponnuvel@gmail.com>
To: Jonny Grant <jg@jguk.org>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: shift-count-overflow possible issue on 64bit type
Date: Sat, 23 Nov 2019 14:16:00 -0000	[thread overview]
Message-ID: <CAOL8xrWt2+a9gVkAFWcP7pEBERFs1qjrOASnbeJq_h0vmo+jPQ@mail.gmail.com> (raw)
In-Reply-To: <9e2a9f57-bdfc-3da3-110d-2f8d51f85b0e@jguk.org>

The shift actually happens as int because the type of 1 is int, and the
result is then assigned to size_t. You can instead use a wider type:

size_t big = 1UL<<41;

On Sat, 23 Nov 2019, 13:56 Jonny Grant, <jg@jguk.org> wrote:

> I see on my 64bit Ubuntu PC that size_t is 8 bytes, that is 64bits,
> however I see a warning:
>
> $ g++-8 -Wall -Wextra -o size_t size_t.cpp
> size_t.cpp: In function ‘int main()’:
> size_t.cpp:11:21: warning: left shift count >= width of type
> [-Wshift-count-overflow]
>       size_t big = 1<<40;
>                       ^~
>
>
>
> Same on Godbolt trunk.
> Is this an issue?
>
> Regards, Jonny
>
> https://godbolt.org/z/xeefQ8
>
> #include <stdio.h>
> size_t big = 1<<41;
>
>
>
> Please keep my email on any replies
> Jonny
>

  reply	other threads:[~2019-11-23 14:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 13:56 Jonny Grant
2019-11-23 14:16 ` Ponnuvel Palaniyappan [this message]
2019-11-24  1:15   ` Jonny Grant
2019-11-25  9:30 ` Jonathan Wakely
2019-11-25 12:02   ` Cristiano Di Buduo
2019-11-26 12:41     ` Jonny Grant
2019-11-25 12:18   ` Florian Weimer
2019-11-25 12:22     ` 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=CAOL8xrWt2+a9gVkAFWcP7pEBERFs1qjrOASnbeJq_h0vmo+jPQ@mail.gmail.com \
    --to=pponnuvel@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jg@jguk.org \
    /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).