PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > New way of doing integer types
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
New way of doing integer types

Réponse
 
LinkBack Outils de la discussion
Vieux 17/01/2008, 14h06   #1
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut New way of doing integer types


I posted an article of similar effect to this to comp.std.c++ but for some
reason it hasn't shown up in the newsgroup.

Anyway, instead of having a system in C++ whereby each integer type has a
minimum range (e.g. int must be at least 16-Bit), would it not be a hell of
a lot better if we could define objects as follows:

uint_fast24_t i;

, where 24 can be replaced with whatever range you need. I think it would
be trivial for a compiler to iterate thru all the integer types it provides
to pick the most appropriate one.

Or perhaps another method could be:

int {0,65535} i; /* 0 and 65535 specify the min and max */

(although personally I prefer the former way of doing it)

This would lead to portable algorithms that run faster.

--
Tomás Ó hÉilidhe
  Réponse avec citation
Vieux 17/01/2008, 14h28   #2
Lars Uffmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

Tomás Ó hÉilidhe wrote:
> Anyway, instead of having a system in C++ whereby each integer type has a
> minimum range (e.g. int must be at least 16-Bit), would it not be a hell of
> a lot better if we could define objects as follows:
>
> uint_fast24_t i;


What do you mean by fast? That the compiler shall do address alignment?

As for the 24 (or whatever else), I am currently using stdint.h, and
types such as uint16_t - what exactly would be different?

Best Regards,

Lars
  Réponse avec citation
Vieux 17/01/2008, 16h37   #3
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

Lars Uffmann:

> Tomás Ó hÉilidhe wrote:
>> Anyway, instead of having a system in C++ whereby each integer type
>> has a minimum range (e.g. int must be at least 16-Bit), would it not
>> be a hell of a lot better if we could define objects as follows:
>>
>> uint_fast24_t i;

>
> What do you mean by fast? That the compiler shall do address
> alignment?
>
> As for the 24 (or whatever else), I am currently using stdint.h, and
> types such as uint16_t - what exactly would be different?
>
> Best Regards,
>
> Lars



uint_fast24_t would represent the fastest integer type that has at least 24
value bits.

By fast, I mean the time it takes for the machine to do arithmetic.


--
Tomás Ó hÉilidhe
  Réponse avec citation
Vieux 17/01/2008, 16h51   #4
Phil Endecott
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

Tomás Ó hÉilidhe wrote:
> Anyway, instead of having a system in C++ whereby each integer type has a
> minimum range (e.g. int must be at least 16-Bit), would it not be a hell of
> a lot better if we could define objects as follows:
>
> uint_fast24_t i;


boost::uint_t<24>::fast i;

> Or perhaps another method could be:
>
> int {0,65535} i; /* 0 and 65535 specify the min and max */


boost::int_max_value_t<65535>::fast i;


Phil.
  Réponse avec citation
Vieux 17/01/2008, 17h14   #5
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

"Tomás Ó hÉilidhe" <toe@lavabit.com> writes:

> I posted an article of similar effect to this to comp.std.c++ but for some
> reason it hasn't shown up in the newsgroup.
>
> Anyway, instead of having a system in C++ whereby each integer type has a
> minimum range (e.g. int must be at least 16-Bit), would it not be a hell of
> a lot better if we could define objects as follows:
>
> uint_fast24_t i;
>
> , where 24 can be replaced with whatever range you need. I think it would
> be trivial for a compiler to iterate thru all the integer types it provides
> to pick the most appropriate one.
>
> Or perhaps another method could be:
>
> int {0,65535} i; /* 0 and 65535 specify the min and max */
>
> (although personally I prefer the former way of doing it)
>
> This would lead to portable algorithms that run faster.


Instead of creating new syntax I'd use a template-like syntax, ie:

#v+
uint_fast<24> i;
int<0, 65535> j;
#v-

The later may be achieved with templates though (probably something
better could be invented but as a proof of concept):

#v+
template<unsigned bits> struct uint {
typedef typename uint<bits + 1>::type type;
};

template<> struct uint< 8> { typedef unsigned char type; }
template<> struct uint<16> { typedef unsigned short type; }
template<> struct uint<32> { typedef unsigned int type; }

uint<24>::type i;
#v-

Not that I believe something like that will be ever implemented even
though it may be handy.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 17/01/2008, 18h03   #6
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

On 2008-01-17 15:06, Tomás Ó hÉilidhe wrote:
> I posted an article of similar effect to this to comp.std.c++ but for some
> reason it hasn't shown up in the newsgroup.
>
> Anyway, instead of having a system in C++ whereby each integer type has a
> minimum range (e.g. int must be at least 16-Bit), would it not be a hell of
> a lot better if we could define objects as follows:
>
> uint_fast24_t i;
>
> , where 24 can be replaced with whatever range you need. I think it would
> be trivial for a compiler to iterate thru all the integer types it provides
> to pick the most appropriate one.
>
> Or perhaps another method could be:
>
> int {0,65535} i; /* 0 and 65535 specify the min and max */
>
> (although personally I prefer the former way of doing it)
>
> This would lead to portable algorithms that run faster.


Yes, and perhaps that is why that is how it is done in C99 and will be
done in C++0X. Though none of them specifies any 24-bit types, just 8,
16,32, and 64 (though I think vendors can add 24 if they want).

--
Erik Wikström
  Réponse avec citation
Vieux 17/01/2008, 18h09   #7
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=:

> Yes, and perhaps that is why that is how it is done in C99 and will be
> done in C++0X. Though none of them specifies any 24-bit types, just 8,
> 16,32, and 64 (though I think vendors can add 24 if they want).



What I was proposing was that you could put in any number you like and then
the compiler would do the work to pick the most appropriate. For example:

uint_fast17_t i;

--
Tomás Ó hÉilidhe
  Réponse avec citation
Vieux 18/01/2008, 10h26   #8
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

Phil Endecott:


> boost::uint_t<24>::fast i;



How can a portable implementation of boost achieve this? Or does boost have
platform-specific implementations?

--
Tomás Ó hÉilidhe
  Réponse avec citation
Vieux 18/01/2008, 12h19   #9
Pete Becker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

On 2008-01-18 05:26:40 -0500, "Tomás Ó hÉilidhe" <toe@lavabit.com> said:

> Phil Endecott:
>
>
>> boost::uint_t<24>::fast i;

>
>
> How can a portable implementation of boost achieve this? Or does boost have
> platform-specific implementations?


Portable code almost always has a platform-specific layer.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

  Réponse avec citation
Vieux 18/01/2008, 14h22   #10
Phil Endecott
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New way of doing integer types

Tomás Ó hÉilidhe wrote:
> Phil Endecott:
>
>> boost::uint_t<24>::fast i;

>
> How can a portable implementation of boost achieve this?


The code's here:

http://svn.boost.org/svn/boost/trunk/boost/integer.hpp

As far as I can see:

- It finds the 'least' type using sizeof, i.e. a 32-bit int when you ask
for 24.
- It typedefs 'least' to 'fast', with a comment that implementations can
override this with a specialisation if they want.
- It doesn't provide any such specialisations.


Phil.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18741 seconds with 18 queries