Partner sites: Aminet - Amiga downloadsIntuitionBase - Amiga guidesAmigaNN - Amiga newsAmiFund - Sponsor projects

[Y]UtilityBase
Your guide to Amiga development
Not logged in
  HomeProjectsForumArticlesResourcesLinksChatAbout 
Search
Login
Username:
Password:
Register now!
Forgot your password?
Aminet - Development
bullet.lha (dev/lib)
MCC_TheBar-26.6.lha (dev/mui)
MCC_TextEditor-15.35.lha (dev/mui)
MCC_BetterString-11.19.lha (dev/mui)
fw_c2p_p2c.lha (dev/lib)
plib_examples.lha (dev/src)
plib.lha (dev/lib)
MCC_NList-0.107.lha (dev/mui)
MCC_NList-0.106.lha (dev/mui)
ruby-1.8.7.i386-aros.tar.bz2 (dev/lang)
More...
Newest users
prowler
apache64 (Chris)
cpeel2300 (Chris)
Branquito
chris (Chris Young)

Pending:
ZebraZeem, Mad_Dog, hhjoker, voxel, JosDuchIt, MarcB, MarBo, Sollaris, sara, species
More...
Who's Online
Online members:

wawa 17 secs ago
kas1e 44 min(s) ago
matthey 50 min(s) ago
ChrisH 58 min(s) ago

9 guests are online.

You are an Anonymous user. You can register for free by clicking here.
News sites
Amiga-News.de
Amiga.org
AmigaNN
Amigans.net
Amigaweb.net
AmigaWorld.net
AROS-Exec
MorphOS-News.de
MorphZone
polarBoing
Tutorials
Change Graphics cards in AmigaOS 4.
Installing the latest OS4 SDK in Cubic IDE
Writing Installer scripts for AmiUpdate
Cross Compiling for OS4 or OS3 using MS Visual Studio 2005
Installing an AmigaOS 4 cross compiler
More...
Sources
How to open and use the exec debug interface
How to install a hardware interrupt
Install SObjs with Installer
How to make clean picture datatypes
Most of the old ClassACT examples converted to OS4
More...
Documentations
How to write portable code for Amiga (english)
Comment écrire du code portable pour Amiga (français)
Development How to with OS3.9 SDK
The PartyPack Hack
The Amiga PDA Programming Guidelines
More...
DreamHost

Support
UtilityBase

[Valid RSS]

UtilityBase needs your help!

AmigaOS Classic - C/C++ development Forum / AmigaOS Classic - C/C++ development /

How big is my int?

 
Author NovaCoder
Forums Member
#1 · Posted: 2010-07-22 01:41 · Edited by: NovaCoder
hiya,

I'm coding a project for Amiga AGA (030 minimum) using GCC v2.95. It has a compiler option to set the size of int to either 16 or 32 bits. I don't think it will actually effect my program as it defines it's own datatypes like this:

[code]
typedef unsigned char byte;

typedef unsigned char uint8;
typedef signed char int8;

typedef unsigned short uint16;
typedef signed short int16;

typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned int uint;
[/code]

But I wondered if there was a standard for classic coding on 030? Also would there be a performance benefit from using a 16 bit int vs a 32 bit int?

Thanx :)

NovaCoder
Author matthey
Forums Member
#2 · Posted: 2010-07-22 03:40
@NovaCoder
There was a speed advantage to using 16 bit integers in many cases on the 68000. The 68020-68040 mostly don't care whether the data is 16 bits or 32 bits although there are a few cases where 32 bits are faster. The 68060 very much prefers 32 bits. It is piped for 32 bits and will be able to use both integer units more often with them. Aztec C used to have 16 bit integers as default with the biggest result being more problems. I would strongly advise leaving integers as 32 bits.
Author NovaCoder
Forums Member
#3 · Posted: 2010-07-22 06:04
Cool, 32bits it is then :)

Thanks :)
Author obarthel
Forums Member
#4 · Posted: 2010-07-22 09:43 · Edited by: obarthel
matthey:
Aztec C used to have 16 bit integers as default with the biggest result being more problems.

Well put :-) The problem with 16 bit integers was that at the time Aztec 'C' implemented the K&R standard, which did not have function prototypes. Hence, you had to cast function parameters to 32 bit integer values if you knew that the respective function expected this (typical example: all AmigaOS operating system functions).

But if you failed to do that for some reason (oversight, typo, etc.), the code crashed very quickly, as the parameters passed over the stack didn't match what the respective function expected to pick up. Just like with assembly language, you had to be extremely careful to get your code written correctly, or you'd have been in for an extended debugging session.

If you use integers smaller than 32 bits today with an ISO 'C' compliant compiler and proper prototypes, the worst that can happen is loss of performance, as the compiler may be forced emit code which promotes smaller integers to larger types before they could be used.
Author Minuous
Forums Member
#5 · Posted: 2010-07-28 05:18
I don't think it will actually affect my program as it defines it's own datatypes like this:

[code]typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned int uint;[/code]

It would indeed affect your program. If you are using 16-bit ints then your uint32, int32 and uint types would actually be only 16 bits wide.
Author NovaCoder
Forums Member
#6 · Posted: 2010-07-30 02:44 · Edited by: NovaCoder
Hiya,

The port has the followind define (commented out by default)

// - Define this if your port needs to use 'long' for the int32 datatype
// (i.e. an integer with exactly 32 bits).
#define SCUMMVM_USE_LONG_INT

Which is used like this:

#ifdef SCUMMVM_USE_LONG_INT
typedef unsigned long uint32;
typedef signed long int32;
typedef unsigned long uint;
#else
typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned int uint;
#endif

Which seems to suggest that the port can run with 16bit precession for supposedly 32bit numbers.
Author obarthel
Forums Member
#7 · Posted: 2010-07-30 09:37
NovaCoder:
The port has the followind define (commented out by default)

That's risky, but then again you never know what kind of compiler environment ScummVM was designed for.

To be absolutely sure about the size of your scalar data types you have to use the compiler's provided definition of uint32_t, etc., which for an ISO 'C' compliant compiler would be found in the "stdint.h" header file. If you're stuck with an old ANSI 'C' compliant compiler, you're on your own, though.
Author Hypex
Forums Member
#8 · Posted: 2010-07-30 14:52 · Edited by: Hypex
NovaCoder

You could test the width with a sizeof().

NovaCoder:
Which seems to suggest that the port can run with 16bit precession for supposedly 32bit numbers.

I notice all these dayatypes seems to assume 32-bits for either long or int. Could it just specify to use an int as a long where both are 32-bits anyway?
 
AmigaOS Classic - C/C++ development Forum / AmigaOS Classic - C/C++ development / How big is my int? Top
Your Reply Click this icon to move up to the quoted message

 

UtilityBase is a site focused on development for Amiga systems,
spanning over all different Amiga clones, that be AmigaOS 3.x, 4.x, MorphOS, AROS or AmigaDE/Anywhere.
News syndication: RSS
Contact address: mail@utilitybase com