Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kleuskes & Moos <kleuske@somewhere.else.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: no warning for assigning unsigned int to plain int |
| Date | 2011-10-12 17:28 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <j74in1$pp3$1@dont-email.me> (permalink) |
| References | <4075cf5b-5ede-472b-8a8f-aaeca4205c8d@l39g2000pro.googlegroups.com> |
On Wed, 12 Oct 2011 07:36:00 -0700, V.Subramanian, India wrote:
> Consider the following program no_warning.c :
>
> #include <stdlib.h>
> #include <stdio.h>
>
> int main()
> {
> size_t length = 4294967295U;
> int size = 4294967295U;
>
> size = length;
>
> return EXIT_SUCCESS;
> }
>
> When I compile this program with
> gcc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.1) as
> gcc -std=c99 -pedantic -Wall -Wextra no_warning.c
> it did not generate any warning.
>
> Consider the statements:
>
> int size = 4294967295U;
>
> size = length;
>
> In both these statements, I am assigning 'unsigned int' to 'plain int'.
> Still the compiler accepts them without issuing any warnings. I am
> unable to understand this.
>
> Please explain.
It should not generate a warning. You invoke an implicit cast from size_t to
int. This is perfectly acceptable according to the C standard. One of the
regulars will undoubtedly provide chapter and verse...
-------------------------------------------------------------------------------
________________________________________
/ Once upon a time, four AMPHIBIOUS HOG \
| CALLERS attacked a family of |
| DEFENSELESS, SENSITIVE COIN COLLECTORS |
| and brought DOWN their PROPERTY |
\ VALUES!! /
----------------------------------------
\
\
___
{~._.~}
( Y )
()~*~()
(_)-(_)
-------------------------------------------------------------------------------
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
no warning for assigning unsigned int to plain int "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-12 07:36 -0700
Re: no warning for assigning unsigned int to plain int James Kuyper <jameskuyper@verizon.net> - 2011-10-12 12:17 -0400
Re: no warning for assigning unsigned int to plain int Kleuskes & Moos <kleuske@somewhere.else.net> - 2011-10-12 17:28 +0000
Re: no warning for assigning unsigned int to plain int Keith Thompson <kst-u@mib.org> - 2011-10-12 12:36 -0700
Re: no warning for assigning unsigned int to plain int Ike Naar <ike@sverige.freeshell.org> - 2011-10-12 17:53 +0000
Re: no warning for assigning unsigned int to plain int Keith Thompson <kst-u@mib.org> - 2011-10-12 12:41 -0700
csiph-web