Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #87104

Re: why use static_cast ?

Path csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: why use static_cast ?
Date Thu, 20 Oct 2022 09:52:19 -0700
Organization None to speak of
Lines 33
Message-ID <87k04u1lq4.fsf@nosuchdomain.example.com> (permalink)
References <tiqa5e$8aju$1@dont-email.me> <035d8c85-23d2-451b-a387-855b369b4c12n@googlegroups.com> <tiqls3$1e6b$1@gioia.aioe.org> <a0bc283b-e719-44ff-b5c4-898f724640a8n@googlegroups.com> <tirsav$ca0u$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain
Injection-Info reader01.eternal-september.org; posting-host="50d90ea39a5d35524253a5bc1ead9c87"; logging-data="408558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZW/KTl+m3GCF8vvMDXAct"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock sha1:mdjDXoyqpKl360vo9Xck5RChKps= sha1:/ky7eXxIu54UVnKEwzmIG2kiZvE=
Xref csiph.com comp.lang.c++:87104

Show key headers only | View raw


Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> On 10/20/2022 4:23 AM, Paul N wrote:
>> On Thursday, October 20, 2022 at 6:21:25 AM UTC+1, Lynn McGuire wrote:
>>> They are both pointers to 8 byte objects. I am just declaring
>>> that I want to use the same address as a 8 byte character string (no
>>> null !) or a long long integer.
>> Isn't that exactly what a union is for? Though if you are hoping to
>> put in values of one type and read them out as values of the other
>> then you would need to check that this is actually defined in your
>> implementation.
>
> "Exactly what a union is for"?
>
> It is true that unions have been used for type punning from time to
> time, but this is not "what a union is for". Union is a 
> memory-time-sharing feature that exists for reducing memory usage. You
> don't normally "put in values of one type and read them out as values
> of the other". That's not exactly what union is for.

Agreed.

K&R1 (1978) introduces unions in section 6.8.  It discusses holding
objects of different types at different times; it says nothing about
type punning.  (The version of C discussed in the 1975 manual didn't
have unions.)

Of course programmers, being programmers, do not tend to restrict
themselves to the original intent of any feature.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web