C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Official c++ 64-bit integer data type

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
cody
Guest





PostPosted: Sun Jul 13, 2003 6:01 am    Post subject: Re: Official c++ 64-bit integer data type Reply with quote



Quote:
Unfortunatly using the same names will not increase portability where
it matters:

int32_t = int16_t + int16_t;

This example will have different results depending on the sizeof(int).


you add datatypes together????
what do you mean here?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Michiel Salters
Guest





PostPosted: Mon Jul 14, 2003 7:10 pm    Post subject: Re: Official c++ 64-bit integer data type Reply with quote



[email]deutronium (AT) gmx (DOT) net[/email] ("cody") wrote in message news:<beqfj3$7u1ck$1 (AT) ID-176797 (DOT) news.uni-berlin.de>...
Quote:
Unfortunatly using the same names will not increase portability where
it matters:

int32_t = int16_t + int16_t;

This example will have different results depending on the sizeof(int).


you add datatypes together????
what do you mean here?

Adding variables of the specified type together, e.g.

int16_t a = 1<<14;
int16_t b = 1<<14;

int32_t c = a + b;

The obvious result would be c = 1<<15, but in the addition
the types will be promoted to int. The result of the addition
will also be an int. Whether or not that overflows still
depends on the exact bitwidth of an int. c==-(1<<15) could
occur if ints are 16 bits.

Regards,
--
Michiel Salters

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Richard Corden
Guest





PostPosted: Mon Jul 14, 2003 9:58 pm    Post subject: Re: Official c++ 64-bit integer data type Reply with quote




Quote:
int32_t = int16_t + int16_t;

This example will have different results depending on the sizeof(int).


you add datatypes together????
what do you mean here?


Sorry for the poor example...

void foo (int16_t a, int16_t b)
{
int32_t result;

result = a + b;
}

So, the value of result may be different for different sizes of int.


Regards

Richard.

--
Richard Corden
To reply remove 's' from address

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
cody
Guest





PostPosted: Thu Jul 17, 2003 1:43 am    Post subject: Re: Official c++ 64-bit integer data type Reply with quote

Quote:
void foo (int16_t a, int16_t b)
{
int32_t result;

result = a + b;
}


you mean in the case if int would be 8 bits then:

300 + 200 = 88 and not 600

because every integral expression where not type ios explicitely specified
results int the int-type?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Philippe Mori
Guest





PostPosted: Mon Jul 21, 2003 6:32 pm    Post subject: Re: Official c++ 64-bit integer data type Reply with quote


""cody"" <deutronium (AT) gmx (DOT) net> a écrit dans le message de
news:bf466n$auf1n$1 (AT) ID-176797 (DOT) news.uni-berlin.de...
Quote:
void foo (int16_t a, int16_t b)
{
int32_t result;

result = a + b;
}


you mean in the case if int would be 8 bits then:

300 + 200 = 88 and not 600

because every integral expression where not type ios explicitely specified
results int the int-type?

--

If you want portable code then you would write something like:

int32_t foo(int16_t a, int16_t bn)
{
int32_t result = a;
result += b;
return result;
}

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
cody
Guest





PostPosted: Tue Jul 22, 2003 10:56 pm    Post subject: Re: Official c++ 64-bit integer data type Reply with quote

Quote:
If you want portable code then you would write something like:

int32_t foo(int16_t a, int16_t bn)
{
int32_t result = a;
result += b;
return result;
}


better would be:

inline int32_t foo(int16_t a, int16_t bn)
{
return (int32_t)a + b;
}

:-D

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.