Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++.moderated > #7298
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Tue, 16 Jun 2015 16:50:01 -0500 |
| Return-Path | <cppmods@glengoyne.dreamhost.com> |
| Sender | lang-cpp-request@vandevoorde.com |
| Approved | c.l.c.m@bazarov.com |
| Message-ID | <GOydnYro6PiNEB3InZ2dnUU7-e-dnZ2d@giganews.com> (permalink) |
| Newsgroups | comp.lang.c++.moderated, comp.lang.c++ |
| From | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
| Subject | Re: Avoid 'int' and associates. |
| Organization | unknown |
| References | <cZOdnSRj9NsZweHInZ2dnUU7-IudnZ2d@giganews.com> <mlna37$md5$1@dont-email.me> <y6OdnUG8htn2rOLInZ2dnUU7-KOdnZ2d@giganews.com> <utVfx.149824$Lj1.95451@fx07.iad> <mlpm56$sg8$1@news.xmission.com> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| X-Original-Date | Tue, 16 Jun 2015 21:54:41 +0100 |
| X-Submission-Address | lang-cpp-submit@vandevoorde.com |
| Date | Tue, 16 Jun 2015 16:47:26 CST |
| Lines | 70 |
| X-Usenet-Provider | http://www.giganews.com |
| X-Trace | sv3-eubXsbpOZbqGg4Hd+G2vxFIT4rtPR8FOsJdfoVgAfukB6kKLUcxxKbY4PFjW/lr3VfSb/CTWWOhXrgW!u5slef90zyGETiQq4GVgOX6dZj9WzVmbySkp+gesNYUrJLPv2sskpuFEZcsNlKgv5yz3qdNAGwvK |
| X-Complaints-To | abuse@giganews.com |
| X-DMCA-Notifications | http://www.giganews.com/info/dmca.html |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 4234 |
| Xref | csiph.com comp.lang.c++.moderated:7298 comp.lang.c++:36505 |
Cross-posted to 2 groups.
Show key headers only | View raw
On 16/06/2015 21:59, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> slp53@pacbell.net spake the secret code
> <utVfx.149824$Lj1.95451@fx07.iad> thusly:
>
>> Granted most of that code ran sans OS (it was the OS), and required
>> fixed types to map to various hardware registers.
>
> This is the situation where I think the size of the data really *does*
> matter and it's important to use sized types and not the implicit size
> of int, long, etc. Things like structures representing byte streams
> passed across the network (and you might do network-to-host byte
> reordering in place on that structure), raw byte streams read from or
> written to files, raw bytes transmitted between processes through
> shared memory segments and so-on.
>
> I've got some code im my open source project that doesn't use
> specifically sized types for some binary file I/O and it's a mess right
> because they used generic types. So I am certainly sympathetic to
> cases where it matters.
>
> My assertion is that it simply doesn't matter in *every* case.
>
>> However, absent API requirements for other types, I would prefer
>> using types for which I understand the characteristics in all
>> conditions, thus I prefer the explicitly sized types. Having
>> run into many issues in the past porting software from 16-bit
>> ints to 32-bit ints (and from 32-bit longs to 64-bit longs),
>> I would never advocating using 'int' for anything.
>
> Here, I disagree. The size of every int in a program isn't a
> portability concern. What's important is deciding which variables need
> specific sizes and which don't.[*]
>
> I've seen code where the compiler's default size of an int was 16-bits
> and everywhere they wanted to iterate over containers or whatnot it was
> int16_t all over the place. Then you move to a compiler where the
> defaault size of an int is 32-bits. The fact that all those ints were
> marked as 16-bits is now erroneous and simply a distraction. How do
> you know which ones really needed to be 16-bits and which were 16-bits
> simply because that was the default size of an int? Forcing them all
> into a 16-bit straight jacket impedes portability instead of enhancing
> it.
This is why you should design things properly perhaps by the use of a
traits class specialized for different hardware which has its own public
typedefs:
template <typename HardwareType>
struct foo_traits;
template <>
struct foo_traits<ZXSpectrum48K>
{
typedef uint16_t index_type;
};
typedef foo_traits<ZXSpectrum48K>::index_type index_type;
/* use index_type rather than uint16_t directly. */
/Flibble
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to comp.lang.c++.moderated | Previous | Next — Previous in thread | Next in thread | Find similar
Avoid 'int' and associates. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2015-06-14 06:36 -0600
Re: Avoid 'int' and associates. Melzzzzz <mel@zzzzz.com> - 2015-06-14 18:00 -0600
Re: Avoid 'int' and associates. Francis Glassborow <francis.glassborow@btinternet.com> - 2015-06-14 18:07 -0600
Re: Avoid 'int' and associates. "James K. Lowden" <jklowden@speakeasy.net> - 2015-06-14 18:11 -0600
Re: Avoid 'int' and associates. James Kuyper <jameskuyper@verizon.net> - 2015-06-14 18:11 -0600
Re: Avoid 'int' and associates. Maciej Sobczak <see.my.homepage@googlemail.com> - 2015-06-14 18:11 -0600
Re: Avoid 'int' and associates. Paavo Helde <myfirstname@osa.pri.ee> - 2015-06-14 20:24 -0600
Re: Avoid 'int' and associates. David Brown <david.brown@hesbynett.no> - 2015-06-15 07:13 -0600
Re: Avoid 'int' and associates. Francis Glassborow <francis.glassborow@btinternet.com> - 2015-06-15 11:22 -0600
Re: Avoid 'int' and associates. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2015-06-15 13:02 -0600
Re: Avoid 'int' and associates. Francis Glassborow <francis.glassborow@btinternet.com> - 2015-06-15 14:54 -0600
Re: Avoid 'int' and associates. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2015-06-15 15:54 -0600
Re: Avoid 'int' and associates. James Kuyper <jameskuyper@verizon.net> - 2015-06-15 21:04 -0600
Re: Avoid 'int' and associates. David Brown <david.brown@hesbynett.no> - 2015-06-16 07:05 -0600
Re: Avoid 'int' and associates. James Kuyper <jameskuyper@verizon.net> - 2015-06-16 14:59 -0600
Re: Avoid 'int' and associates. David Brown <david.brown@hesbynett.no> - 2015-06-16 16:47 -0600
Re: Avoid 'int' and associates. scott@slp53.sl.home (Scott Lurndal) - 2015-06-16 09:54 -0600
Re: Avoid 'int' and associates. legalize+jeeves@mail.xmission.com (Richard) - 2015-06-16 14:59 -0600
Re: Avoid 'int' and associates. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2015-06-16 16:47 -0600
Re: Avoid 'int' and associates. "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-06-16 15:03 -0600
Re: Avoid 'int' and associates. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2015-06-16 16:47 -0600
Re: Avoid 'int' and associates. pip010 <pip010@googlemail.com> - 2015-08-03 06:54 -0600
Re: Avoid 'int' and associates. maddoxr@acm.org - 2015-08-03 10:01 -0600
Re: Avoid 'int' and associates. James Kuyper <jameskuyper@verizon.net> - 2015-06-15 21:04 -0600
Re: Avoid 'int' and associates. James Kuyper <jameskuyper@verizon.net> - 2015-06-15 15:55 -0600
Re: Avoid 'int' and associates. David Brown <david.brown@hesbynett.no> - 2015-06-16 07:04 -0600
Re: Avoid 'int' and associates. Öö Tiib <ootiib@hot.ee> - 2015-06-27 14:17 -0600
csiph-web