🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #309888

Re: W której wersji standardu C lub C++ pracujecie?

#309888
From: Maciek Godek
Date: Mon, 12 Aug 2019 06:15
49 lines
2840 bytes
W dniu niedziela, 11 sierpnia 2019 20:12:34 UTC+2 użytkownik PawelS pawel(at)wbcd(dot)pl napisał:
> Maciek Godek pisze:
> > W dniu wtorek, 6 sierpnia 2019 14:02:33 UTC+2 użytkownik Queequeg napisał:
> > To ważne, bo ani -Wall ani nawet -Wextra w GCC nie wyłapie czegoś takiego:
> > 
> > uint32_t f() {
> >   return JAKAŚ_DUŻA_WARTOŚĆ;
> > }
> > 
> > uint16_t x = f();
> > 
> > (co uważam że jest skandaliczne i byłem w szoku jak to odkryłem. Zresztą nadal jestem w szoku)
> 
> A to ciekawe, bo bez żadnych opcji gcc zgłasza ostrzeżenie:
> 
> gcc -v
> ------
> gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)
> 
> test.c
> ------
> #include <stdint.h>
> uint32_t f() {
>          return 0xffffffffffff;
> }
> int main() {
>          uint16_t x = f();
>          return 0;
> }
> 
> gcc -o test test.c
> ------------------
> test.c: In function 'f':
> test.c:3: warning: integer constant is too large for 'long' type
> test.c:3: warning: large integer implicitly truncated to unsigned type

W tym przykładzie zgłasza błąd konwersji stałej. Zamiast tego spróbuj np.

#include <stdint.h>
uint32_t f(uint32_t x) {
  return x*x;
}
int main(int argc, char *argv[]) {
         uint16_t x = f(argc);
         return 0;
}

U mnie na telefonie (gcc 6) jest milczenie, choć typ zmiennej ewidentnie się nie zgadza z typem funkcji.
(Dopiero -Wconversion pomaga)
Technical Details
Message-ID: <d897b352-477c-42c0-ae44-f2df4bda7361@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!feeder.erje.net!2.eu.feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!b26no999842qtq.0!news-out.google.com!d29ni1158qtg.1!nntp.google.com!b26no999834qtq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <a1fbe21b-aed9-4b32-9691-a824c4e31a21@trust.no1> <3f1215b5-3c16-4248-a74f-1b57d21d4c98@googlegroups.com> <5d505a6e$0$17364$65785112@news.neostrada.pl>

Show Full Headers
Complete Article Headers
X-Received: by 2002:ac8:6b41:: with SMTP id x1mr29398015qts.246.1565590547019;        Sun, 11 Aug 2019 23:15:47 -0700 (PDT)
X-Received: by 2002:a25:d70e:: with SMTP id o14mr18059730ybg.440.1565590546835; Sun, 11 Aug 2019 23:15:46 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!feeder.erje.net!2.eu.feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!b26no999842qtq.0!news-out.google.com!d29ni1158qtg.1!nntp.google.com!b26no999834qtq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Sun, 11 Aug 2019 23:15:46 -0700 (PDT)
In-Reply-To: <5d505a6e$0$17364$65785112@news.neostrada.pl>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.25.230.172; posting-account=f7iIKQoAAAAkDKpUafc-4IXhmRAzdB5r
NNTP-Posting-Host: 83.25.230.172
References: <a1fbe21b-aed9-4b32-9691-a824c4e31a21@trust.no1> <3f1215b5-3c16-4248-a74f-1b57d21d4c98@googlegroups.com> <5d505a6e$0$17364$65785112@news.neostrada.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d897b352-477c-42c0-ae44-f2df4bda7361@googlegroups.com>
Subject: Re: W której wersji standardu C lub C++ pracujecie?
From: Maciek Godek <godek.maciek@gmail.com>
Injection-Date: Mon, 12 Aug 2019 06:15:47 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit