short int in C
short int in C
My teacher insists on saying that a short int in C is going to be 2 bytes 'long' in all architectures, I could have sworn I have read many many times that C ints are in no way standar in all architectures.... some of you may have a 64 bit computer/compiler, whats the length of a short int?
Not yet.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
ANSI requires short ints to be at least 16 bits, and no longer than ints. There's no express or implied maximum size for short int; you have to check <limits.h>
If he's making the statement, it's presumably up to him to convince you with evidence from the spec. C99 introduced the <stdint.h> fixed width integers precisely so people could avoid these unproductive debates.
If he's making the statement, it's presumably up to him to convince you with evidence from the spec. C99 introduced the <stdint.h> fixed width integers precisely so people could avoid these unproductive debates.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Are those supported by VS by now? I'm still on VS 2005 where those had been missing (6 years was probably just not enough time to add something as complicated as new integer types...)rogerborg wrote:C99 introduced the <stdint.h> fixed width integers precisely so people could avoid these unproductive debates.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LOL..CuteAlien wrote:Are those supported by VS by now? I'm still on VS 2005 where those had been missing (6 years was probably just not enough time to add something as complicated as new integer types...)rogerborg wrote:C99 introduced the <stdint.h> fixed width integers precisely so people could avoid these unproductive debates.
I'm using VC9. Tell me where to check and I'll post here what you need.
Integer variables are a very confusing issue for newcomers to the C/C++ language or to any programmer whom have only required the use of one compiler on a individual platform. The <limits.h> or <climits> in newer C++ compilers provides information about integer types that may be used by your program at run time. Yet a C++ compiler is not required to include <limits.h>, yet that is not to say the gross majority do not in fact I cannot think of a single compiler that would not include <limits.h> unless having an extremely good reason for doing so.
I would recommend searching through the manual pages or documentation of your compiler as each compiler must document its implementation. I know this may seem like quite a tedious activity but it may be something worth looking into on a rainy afternoon. For example I believe the compiler behind Dev C++ has the same size for a int and long variable.
I hope this information has been some help to you. If you would like a useful resource I used while composing this post I would recommend taking a look at: http://home.att.net/~jackklein/c/inttypes.html
Thanks.
I would recommend searching through the manual pages or documentation of your compiler as each compiler must document its implementation. I know this may seem like quite a tedious activity but it may be something worth looking into on a rainy afternoon. For example I believe the compiler behind Dev C++ has the same size for a int and long variable.
I hope this information has been some help to you. If you would like a useful resource I used while composing this post I would recommend taking a look at: http://home.att.net/~jackklein/c/inttypes.html
Thanks.
Programming Blog: http://www.uberwolf.com
I just searched around a little and found some more info on stdint.h on the wiki: http://en.wikipedia.org/wiki/Stdint.h
Implementations for VS are offered by now from external parties. Though it does mention some problems with printf (and maybe the same with streaming?) so the new types should probably still be used with some care.
Implementations for VS are offered by now from external parties. Though it does mention some problems with printf (and maybe the same with streaming?) so the new types should probably still be used with some care.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Hmm, you're right; I can't find a minimum size for short int in C99. K&R ANSI C guaranteed at least 16 bits.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
I'd have to check the documents , but I'm pretty sure rogerborg is right. I think that C89 and C99 required that a short be able to represent -32767 to 32767 and that it be able to represent all of the values represented by a char. The first requirement implies at least 16-bits of representation, but the actual size of the type could be larger. It wouldn't be efficient, but it would be compliant.
Travis
Travis
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Ah, that's it. C99 5.2.4.2 specifies minimum magnitudes for limits.h, and SHRT_MIN / SHRT_MAX are indeed -32767 and +32767.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Being wrong is an opportunity to learn. Learning is what separates us from the animals, or Republicans.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 34
- Joined: Sat Mar 08, 2008 12:46 pm
- Location: Germany, FFM
- Contact:
so true....,or Republicans.
if life could only be written in C++...
so much features, money++, remove_childs(), choose parents, life = new life, and no more <IDIOT> templates !
if you're looking for an nerdy coding language: http://lolcode.com/
so much features, money++, remove_childs(), choose parents, life = new life, and no more <IDIOT> templates !
if you're looking for an nerdy coding language: http://lolcode.com/