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


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

Re: C++ variable names

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: C++ variable names
Date 2020-01-16 10:08 +0100
Organization A noiseless patient Spider
Message-ID <qvp95v$45c$1@dont-email.me> (permalink)
References (1 earlier) <4d6f2d19-ff6f-433c-bff9-adde1c8b719a@googlegroups.com> <qvoipk$1bd$1@dont-email.me> <nb102f93tq0r8lav6tk8d51cdh9ihu33ik@4ax.com> <qvp1lg$u6u$1@dont-email.me> <h8aiiqF5fpiU1@mid.individual.net>

Show all headers | View raw


On 16/01/2020 08:44, Bo Persson wrote:

> If you limit yourself to Windows, this becomes a lot easier as you can
> just look up what the built in types are there - you can use short for
> 16 bits, int and unsigned for 32-bits, and long long when you need 64-bits.
> 

I believe even MSVC, with its poor support for C99, has <stdint.h>.
There are /no/ advantages in using types like "short" and "long long"
over the standard sized types when you want specific sized types.  If
you want a signed 16-bit type, you use "int16_t" - you don't write
something completely different ("short") and assume it matches, even if
that assumption is perfectly valid.  This is about writing code in a way
that is clear - it cannot possibly be misinterpreted by any compiler, or
by any reader.  If you write "long", the size can change between
platforms - and even on the one platform, programmers used to different
platforms might misread it.  If you write "uint32_t", there is no
possibility of mistakes.

This is why these types were added to C - use them.

> The _t-types in the standard libary are for when *you* want to write a
> library for a wide set of systems and you don't know what type is 32
> bits wide (if any).
> 
> One (very small) advantage of using int32_t is that it will not compile
> if you happen to try out your code on a 36-bit computer. But that never
> happens anyway if you use Windows.
> 
A marginally more realistic advantage is that "int8_t" won't compile on
platforms with CHAR_BIT greater than 8 (and unlike 36-bit computers,
such processors are in wide use today - though not, obviously, running
Windows).  And "int64_t" won't compile on platforms that don't support
64-bit types (for some limited compilers that don't support full C99).

In general, if you want a size-specific type, along with the additional
guarantees of two's complement integers with no padding bits, use the
size-specific types in <stdint.h>.  Then you get what you ask for, the
code is clear, and you'll get a hard failure if the compiler can't give
you what you want.

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


Thread

C++ variable names T <T@invalid.invalid> - 2020-01-15 18:31 -0800
  Re: C++ variable names Daniel <danielaparker@gmail.com> - 2020-01-15 18:42 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 18:46 -0800
      Re: C++ variable names Daniel <danielaparker@gmail.com> - 2020-01-15 21:30 -0800
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 21:52 -0800
      Re: C++ variable names Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2020-01-15 23:44 -0700
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 22:59 -0800
          Re: C++ variable names Bo Persson <bo@bo-persson.se> - 2020-01-16 08:44 +0100
            Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 23:48 -0800
            Re: C++ variable names David Brown <david.brown@hesbynett.no> - 2020-01-16 10:08 +0100
          Re: C++ variable names Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2020-01-16 00:43 -0700
            Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 23:51 -0800
              Re: C++ variable names Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2020-01-16 01:39 -0700
                Re: C++ variable names T <T@invalid.invalid> - 2020-01-16 14:01 -0800
    Re: C++ variable names Lynn McGuire <lynnmcguire5@gmail.com> - 2020-01-16 15:48 -0600
      Re: C++ variable names Öö Tiib <ootiib@hot.ee> - 2020-01-16 14:11 -0800
        Re: C++ variable names Lynn McGuire <lynnmcguire5@gmail.com> - 2020-01-17 18:52 -0600
        Re: C++ variable names Manfred <noname@add.invalid> - 2020-01-18 16:22 +0100
          Re: C++ variable names Öö Tiib <ootiib@hot.ee> - 2020-01-18 10:41 -0800
          Re: C++ variable names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-01-21 05:31 -0800
      Re: C++ variable names David Brown <david.brown@hesbynett.no> - 2020-01-16 23:32 +0100
      Re: C++ variable names legalize+jeeves@mail.xmission.com (Richard) - 2020-01-19 19:13 +0000
  Re: C++ variable names red floyd <no.spam@its.invalid> - 2020-01-15 18:45 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 18:47 -0800
    Re: C++ variable names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-01-15 21:51 -0800
      Re: C++ variable names red floyd <no.spam@its.invalid> - 2020-01-15 22:44 -0800
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 23:00 -0800
  Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 19:40 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 19:58 -0800
      Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 20:12 -0800
    Re: C++ variable names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-15 23:18 -0500
      Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 20:20 -0800
        Re: C++ variable names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-16 12:06 -0800
          Re: C++ variable names T <T@invalid.invalid> - 2020-01-16 14:02 -0800
      Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 20:31 -0800
        Re: C++ variable names David Brown <david.brown@hesbynett.no> - 2020-01-16 11:09 +0100
  Re: C++ variable names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-16 03:52 +0000
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 19:59 -0800
      Re: C++ variable names Bo Persson <bo@bo-persson.se> - 2020-01-16 06:33 +0100
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 21:53 -0800
  Re: C++ variable names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-16 06:18 +0100
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 21:54 -0800
      Re: C++ variable names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-16 06:59 +0100
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 22:31 -0800
          Re: C++ variable names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-01-16 00:15 -0800
          Re: C++ variable names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-16 11:25 +0100
            Re: C++ variable names Mister2U@honorific.org - 2020-01-16 11:47 +0000
              Re: C++ variable names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-16 13:31 +0100
                Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-16 15:51 -0800
                Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-16 15:51 -0800
                Re: C++ variable names Manfred <invalid@add.invalid> - 2020-01-17 01:31 +0100
  Re: C++ variable names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-01-15 21:48 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 21:55 -0800
      Re: C++ variable names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-01-16 00:01 -0800
    Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 22:28 -0800
      Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 22:31 -0800
  Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 23:16 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 23:26 -0800
      Re: C++ variable names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-15 23:34 -0800
        Re: C++ variable names T <T@invalid.invalid> - 2020-01-15 23:53 -0800
          Re: C++ variable names Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2020-01-16 03:04 -0700
  C++ variable names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-16 11:51 -0800
    Re: C++ variable names T <T@invalid.invalid> - 2020-01-16 13:58 -0800

csiph-web