Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87080 > unrolled thread
| Started by | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| First post | 2022-10-19 21:01 -0500 |
| Last post | 2022-10-20 13:21 -0500 |
| Articles | 4 on this page of 64 — 22 participants |
Back to article view | Back to comp.lang.c++
why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-19 21:01 -0500
Re: why use static_cast ? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-19 19:40 -0700
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-20 00:21 -0500
Re: why use static_cast ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-19 23:21 -0700
Re: why use static_cast ? Juha Nieminen <nospam@thanks.invalid> - 2022-10-20 07:19 +0000
Re: why use static_cast ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-20 00:21 -0700
Re: why use static_cast ? Paul N <gw7rib@aol.com> - 2022-10-20 04:23 -0700
Re: why use static_cast ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-10-20 14:14 +0100
Re: why use static_cast ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-20 09:17 -0700
Re: why use static_cast ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-10-20 09:52 -0700
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-15 17:10 -0800
Re: why use static_cast ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-16 09:26 +0000
Re: why use static_cast ? David Brown <david.brown@hesbynett.no> - 2022-11-16 14:36 +0100
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-20 05:54 -0800
Re: why use static_cast ? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-20 08:11 -0700
Re: why use static_cast ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-19 20:09 -0700
Re: why use static_cast ? Juha Nieminen <nospam@thanks.invalid> - 2022-10-20 05:44 +0000
Re: why use static_cast ? Gawr Gura <gawrgura@mail.hololive.com> - 2022-10-20 14:50 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 17:53 +0300
Re: why use static_cast ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-10-20 08:52 +0200
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 17:52 +0300
Re: why use static_cast ? scott@slp53.sl.home (Scott Lurndal) - 2022-10-20 13:55 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 17:55 +0300
Re: why use static_cast ? scott@slp53.sl.home (Scott Lurndal) - 2022-10-20 15:01 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 18:32 +0300
Re: why use static_cast ? scott@slp53.sl.home (Scott Lurndal) - 2022-10-20 16:07 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 20:14 +0300
Re: why use static_cast ? scott@slp53.sl.home (Scott Lurndal) - 2022-10-20 17:30 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 20:41 +0300
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-21 14:05 -0500
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-22 00:09 +0300
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-22 08:47 +0300
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-22 15:03 -0500
Re: why use static_cast ? Muttley@dastardlyhq.com - 2022-10-23 07:35 +0000
Re: why use static_cast ? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-23 15:28 +0300
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-23 14:13 -0500
Re: why use static_cast ? Manfred <noname@add.invalid> - 2022-10-23 20:27 +0200
Re: why use static_cast ? Michael S <already5chosen@yahoo.com> - 2022-10-23 15:04 -0700
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-23 23:14 -0500
Re: why use static_cast ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-10-21 17:21 +0200
Re: why use static_cast ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-10-21 17:24 +0200
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-20 13:21 -0500
Re: why use static_cast ? Manfred <noname@add.invalid> - 2022-10-21 05:52 +0200
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-21 13:59 -0500
Re: why use static_cast ? Bo Persson <bo@bo-persson.se> - 2022-10-22 18:31 +0200
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-22 15:05 -0500
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-22 17:34 -0500
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-02 17:54 -0700
Re: why use static_cast ? Öö Tiib <ootiib@hot.ee> - 2022-11-03 08:51 -0700
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-15 16:19 -0800
Re: why use static_cast ? Öö Tiib <ootiib@hot.ee> - 2022-11-15 23:02 -0800
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-20 05:59 -0800
Re: why use static_cast ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-20 15:05 +0100
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-20 07:22 -0800
Re: why use static_cast ? Öö Tiib <ootiib@hot.ee> - 2022-11-20 08:40 -0800
Re: why use static_cast ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-28 20:43 -0800
Re: why use static_cast ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-04 07:27 +0000
Re: why use static_cast ? scott@slp53.sl.home (Scott Lurndal) - 2022-11-04 13:47 +0000
Re: why use static_cast ? Vir Campestris <vir.campestris@invalid.invalid> - 2022-11-05 21:34 +0000
Re: why use static_cast ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-11-06 03:25 -0500
Re: why use static_cast ? Paavo Helde <eesnimi@osa.pri.ee> - 2022-11-06 17:34 +0200
Re: why use static_cast ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-07 07:13 +0000
Re: why use static_cast ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 09:09 -0700
Re: why use static_cast ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-20 13:21 -0500
Page 4 of 4 — ← Prev page 1 2 3 [4]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2022-11-06 17:34 +0200 |
| Message-ID | <tk8k5i$3672u$1@dont-email.me> |
| In reply to | #87229 |
04.11.2022 15:47 Scott Lurndal kirjutas: > Juha Nieminen <nospam@thanks.invalid> writes: >> Scott Lurndal <scott@slp53.sl.home> wrote: >>> Young C++ programmers don't understand C, so they think >>> that static_cast<fem::str<8>*> is more "readable". Heh. >> >> So your opinion on what's "readable" and what isn't is better than my >> opinion on the subject because... why? > > It's an opinion. You know the old saying. > >> >> I'm 99% certain that the main (if not even only) reason why you don't like >> static_cast is because it's longer. That's it. No other reason. > > Actually, I don't like it because it doesn't add anything useful over > a plain c-style cast. But it does. If I get e.g. constness wrong in my casting, a C-style cast won't bat an eye whereas static_cast will complain loudly. Ditto for many other mistakes which I might make. If you never make any mistakes when typing code, then it does not matter, but for me it does.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2022-11-07 07:13 +0000 |
| Message-ID | <tkab7j$1bm8$1@gioia.aioe.org> |
| In reply to | #87268 |
Paavo Helde <eesnimi@osa.pri.ee> wrote: > 04.11.2022 15:47 Scott Lurndal kirjutas: >> Juha Nieminen <nospam@thanks.invalid> writes: >>> Scott Lurndal <scott@slp53.sl.home> wrote: >>>> Young C++ programmers don't understand C, so they think >>>> that static_cast<fem::str<8>*> is more "readable". Heh. >>> >>> So your opinion on what's "readable" and what isn't is better than my >>> opinion on the subject because... why? >> >> It's an opinion. You know the old saying. >> >>> >>> I'm 99% certain that the main (if not even only) reason why you don't like >>> static_cast is because it's longer. That's it. No other reason. >> >> Actually, I don't like it because it doesn't add anything useful over >> a plain c-style cast. > > But it does. If I get e.g. constness wrong in my casting, a C-style cast > won't bat an eye whereas static_cast will complain loudly. Ditto for > many other mistakes which I might make. If you never make any mistakes > when typing code, then it does not matter, but for me it does. Indeed. In some cases eg. casting away constness may not only lead to bugs, but in fact be UB. Such as casting away the constness of a char pointer pointing to a string literal, and then trying to modify the contents of that string. With static_cast the compiler will tell you that you are trying to cast away constness, and it may immediately indicate your error. With a C style cast you might never notice, and the program may even seem to work fine... until one day it doesn't.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2022-11-04 09:09 -0700 |
| Message-ID | <877d0an1la.fsf@nosuchdomain.example.com> |
| In reply to | #87223 |
Juha Nieminen <nospam@thanks.invalid> writes:
> Scott Lurndal <scott@slp53.sl.home> wrote:
>> Young C++ programmers don't understand C, so they think
>> that static_cast<fem::str<8>*> is more "readable". Heh.
>
> So your opinion on what's "readable" and what isn't is better than my
> opinion on the subject because... why?
>
> I'm 99% certain that the main (if not even only) reason why you don't like
> static_cast is because it's longer. That's it. No other reason.
>
> I have noticed a very common psychological phenomenon that for some
> reason beginner programmers try to write code that's as short as possible,
> even when that comes at the cost of legibility (a phenomenon that I have
> named "the brevity-over-clarity style of programming"). Way too many
> programmers never learn out of this bad habit.
Wouldn't it be better to call it the BOCSOP? 8-)}
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-10-20 13:21 -0500 |
| Message-ID | <tis3jv$ct2g$2@dont-email.me> |
| In reply to | #87080 |
On 10/19/2022 9:01 PM, Lynn McGuire wrote: > I put the following cast into my code and one of my programmers wants me > to use static cast. Why ? > https://en.cppreference.com/w/cpp/language/static_cast > > longint nfac [8]; > fem::str <8> * nfac_str = (fem::str <8> *) nfac; > > fem::str <8> is an 8 character object that acts like a Fortran > character*8. longint is a long long. > > Thanks, > Lynn Thanks to all for the views ! They were good. Lynn
[toc] | [prev] | [standalone]
Page 4 of 4 — ← Prev page 1 2 3 [4]
Back to top | Article view | comp.lang.c++
csiph-web