 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
cody Guest
|
Posted: Sun Jul 13, 2003 6:01 am Post subject: Re: Official c++ 64-bit integer data type |
|
|
| 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
|
Posted: Mon Jul 14, 2003 7:10 pm Post subject: Re: Official c++ 64-bit integer data type |
|
|
[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
|
Posted: Mon Jul 14, 2003 9:58 pm Post subject: Re: Official c++ 64-bit integer data type |
|
|
| 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
|
Posted: Thu Jul 17, 2003 1:43 am Post subject: Re: Official c++ 64-bit integer data type |
|
|
| 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
|
Posted: Mon Jul 21, 2003 6:32 pm Post subject: Re: Official c++ 64-bit integer data type |
|
|
""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
|
Posted: Tue Jul 22, 2003 10:56 pm Post subject: Re: Official c++ 64-bit integer data type |
|
|
| 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 |
|
 |
|
|
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
|
|