Article View: pl.comp.lang.c
Article #309889Re: W której wersji standardu C lub C++ pracujecie?
From: PawelS pawel(at)wbcd(dot)pl
Date: Tue, 13 Aug 2019 16:08
Date: Tue, 13 Aug 2019 16:08
71 lines
3453 bytes
3453 bytes
Maciek Godek pisze:
> 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)
gcc -o test test.c
------------------
gcc -o test test.c -Wconversion
-------------------------------
test.c: In function ‘main’:
test.c:6: warning: passing argument 1 of ‘f’ as unsigned due to prototype
> choć typ zmiennej ewidentnie się nie zgadza z typem funkcji.
/usr/include/stdint.h
typedef unsigned int uint32_t;
Być może powinien tutaj zabrać głos ktoś bardziej kompetentny,
ale "int" od "unsigned int" a różni się tylko znakiem,
także moim zdaniem ewidentna niezgodność typów danych to byłoby:
"double" vs "int", "char *" vs "int", "struct ..." vs "int",
Ten znak to kwestia wyświetlania oraz porównywania wartości,
sam często muszę char rzutować na unsigned char,
aby wartości powyżej 127 nie były wyświetlanie jako 0xffffff..,
przy porównywaniu również będą ciekawe rezultaty.
Technical Details
Message-ID:
<5d52e072$0$521$65785112@news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mailReferences:
<a1fbe21b-aed9-4b32-9691-a824c4e31a21@trust.no1> <3f1215b5-3c16-4248-a74f-1b57d21d4c98@googlegroups.com> <5d505a6e$0$17364$65785112@news.neostrada.pl> <d897b352-477c-42c0-ae44-f2df4bda7361@googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail Date: Tue, 13 Aug 2019 18:08:17 +0200 From: "PawelS pawel(at)wbcd(dot)pl" <fake@email.org> User-Agent: Thunderbird 2.0.0.18 (X11/20081120) MIME-Version: 1.0 Newsgroups: pl.comp.lang.c Subject: Re: W której wersji standardu C lub C++ pracujecie? References: <a1fbe21b-aed9-4b32-9691-a824c4e31a21@trust.no1> <3f1215b5-3c16-4248-a74f-1b57d21d4c98@googlegroups.com> <5d505a6e$0$17364$65785112@news.neostrada.pl> <d897b352-477c-42c0-ae44-f2df4bda7361@googlegroups.com> In-Reply-To: <d897b352-477c-42c0-ae44-f2df4bda7361@googlegroups.com> Lines: 71 Message-ID: <5d52e072$0$521$65785112@news.neostrada.pl> Organization: Telekomunikacja Polska NNTP-Posting-Host: 89.231.96.70 X-Trace: 1565712498 unt-rea-a-02.news.neostrada.pl 521 89.231.96.70:42461 X-Complaints-To: abuse@news.neostrada.pl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit