Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #152579
| From | Real Troll <real.troll@trolls.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: What is the rank of size_t ? |
| Date | 2020-06-01 01:45 -1000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <rb2ppj$155s$1@gioia.aioe.org> (permalink) |
| References | <y88BWrDFndCB41zt@bongo-ra.co> <raop58$1hn8$1@gioia.aioe.org> <86pnamrs9r.fsf@linuxsc.com> <rau761$8og$1@gioia.aioe.org> <86k10rpqum.fsf@linuxsc.com> |
On 01/06/2020 01:33, Tim Rentsch wrote:
> Real Troll <Real.Troll@trolls.com> writes:
>
>> On 30/05/2020 04:55, Tim Rentsch wrote:
>>
>>> Real Troll <real.troll@trolls.com> writes:
>>>
>>>> On 27/05/2020 13:49, Spiros Bousbouras wrote:
>>>>
>>>>> Specifically , if a has type int and b has type size_t , can
>>>>> a + b overflow i.e. cause undefined behaviour ?
>>>> Try running this program to see what happens? I use 64 bit compiler on
>>>> a 64 bit machine:
>>>>
>>>> <******************************************************************>
>>>>
>>>> #include <stdio.h>
>>>> #include <stdlib.h>
>>>> #include <limits.h>
>>>> #include <float.h>
>>>>
>>>> int main(void)
>>>> {
>>>> const size_t N = 18446744073709551615;
>>>> int a = 100;
>>>> size_t result = N + a;
>>>> printf("SIZE_MAX is: = %zu\n", SIZE_MAX);
>>>> printf("Value of result (N + a) = %zu\n", result);
>>>>
>>>> return 0;
>>>> }
>>>>
>>>> <******************************************************************>
>>> Do you get two program errors? That's what I get.
>> No errors in Visual Studio 2019. [...]
> Well that explains at least some of it. What do you get if
> you run this:
>
> #include <stdio.h>
> #include <stdint.h>
>
> int
> main(){
> printf( "INTMAX_MAX is %td\n", INTMAX_MAX );
> return 0;
> }
>
> ?
On a 64 bit machine using 64 bit compiler:
INTMAX_MAX is 9223372036854775807
For 32 bit compiler (on 64 bit machine), I was getting errors but I made
small changes and I got:
INTMAX_MAX is 9223372036854775807
The changes I made were:
printf("INTMAX_MAX is %I64d\n", INTMAX_MAX);
printf("INTMAX_MAX is %lld\n", INTMAX_MAX);
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
What is the rank of size_t ? Spiros Bousbouras <spibou@gmail.com> - 2020-05-27 12:49 +0000
Re: What is the rank of size_t ? Spiros Bousbouras <spibou@gmail.com> - 2020-05-27 13:54 +0000
Re: What is the rank of size_t ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-05-27 11:14 -0400
Re: What is the rank of size_t ? Spiros Bousbouras <spibou@gmail.com> - 2020-05-27 19:03 +0000
Re: What is the rank of size_t ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-05-27 18:09 -0400
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-05-30 01:54 -0700
Re: What is the rank of size_t ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-05-27 09:59 -0400
Re: What is the rank of size_t ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-05-27 07:37 -0700
Re: What is the rank of size_t ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-05-27 11:02 -0400
Re: What is the rank of size_t ? Vir Campestris <vir.campestris@invalid.invalid> - 2020-05-27 20:46 +0100
Re: What is the rank of size_t ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-05-27 14:30 -0700
Re: What is the rank of size_t ? Real Troll <real.troll@trolls.com> - 2020-05-28 06:35 -1000
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-05-29 20:55 -0700
Re: What is the rank of size_t ? Real Troll <Real.Troll@trolls.com> - 2020-05-30 08:05 -1000
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-05-31 17:33 -0700
Re: What is the rank of size_t ? Real Troll <real.troll@trolls.com> - 2020-06-01 01:45 -1000
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-06-03 11:33 -0700
Re: What is the rank of size_t ? Ike Naar <ike@otaku.sdf.org> - 2020-06-01 20:51 +0000
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-06-03 11:16 -0700
Re: What is the rank of size_t ? raltbos@xs4all.nl (Richard Bos) - 2020-05-31 09:12 +0000
Re: What is the rank of size_t ? Real Troll <reasl.troll@trolls.com> - 2020-05-31 01:30 -1000
Re: What is the rank of size_t ? raltbos@xs4all.nl (Richard Bos) - 2020-06-04 20:40 +0000
Re: What is the rank of size_t ? Real Troll <real.troll@trolls.com> - 2020-06-04 12:50 -1000
Re: What is the rank of size_t ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-05-30 00:55 -0700
Re: What is the rank of size_t ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-06-02 10:06 +0200
csiph-web