The size of the 'int' type depends on the target platform and the compiler used. Usually it's 32-bit on 32-bit platforms and 64-bit on 64-bit ones. The C standard only requires that an 'int' must be at least 16 bits so if you use a really old compiler the 'int' might be just 16-bit.
The other builtin types like short and long f.e. are defined in a similar which is why if you really need a specific bit size for a variable you are better off using types like (u)int8_t, (u)int16_t (u)int32_t, ... as defined by the C library includes or (u)int8, (u)int16, (u)int32, ... as defined by "exec/types.h".
Usually it should be 32 bits wide and hence take 4 bytes.
Use something like "printf("%d\n", sizeof(int));" to be really sure. Types like "int" or "short" are very system specific and their size may vary between different platforms.
int8 is what we call a "char" int16 is what we call a "short".
The configure script used by many open source programs often detects the length of “types” before you compile.
If your new to C or C++, be aware of signed and unsigned variables.
16bit unsigned hex number 0xFFFF is not -1, but a signed 16bit hex number 0xFFFF is -1.
The compiler normally yield warning when you set a signed to unsigned variable or opposite, it should not be ignored, unless you know it won’t be a problem.
Edited by LiveForIt on 2012/9/17 20:10:59
(NutsAboutAmiga)
Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
MC68000 only featured d0-d15 data pins on the outside (16 data bits), it required 32bit data to be written in two operations, while CPU was called a 16bit cpu, instruction set and registers was 32bit, the address lines on the outside ranged from A0-A23 (24bit).
The number of address lines or data lines does not reflect the instruction set or registers! But number of address lines does limit the physical address space, and number data lines does reflect how many operations it’s going to take to write the data to memory (So even more important to try to keep thins in registers when its 32bit, or use 16 bit data width when you need work whit memory).
Edited by LiveForIt on 2012/9/25 8:52:08 Edited by LiveForIt on 2012/9/25 8:53:45
(NutsAboutAmiga)
Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
does not use the register as count but stores the value in a memory address, so the number of bits on outside of processor is probably more important than the number of bits in the registers.
Anyway if really wont the compiler to optimize for using registers.
You need to define your int as:
Register int cnt;
however there is a limited number of registers and so there is limited of what compiler will put in there.
(NutsAboutAmiga)
Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Anyway if really wont the compiler to optimize for using registers.
You need to define your int as:
Register int cnt;
however there is a limited number of registers and so there is limited of what compiler will put in there.
A decent compiler will take care of this for you. "register" as a keyword is basically obsolete and has been for years. Likewise a good compiler will use registers for loop counters etc, automatically.
Anyway if really wont the compiler to optimize for using registers.
You need to define your int as:
Register int cnt;
however there is a limited number of registers and so there is limited of what compiler will put in there.
A decent compiler will take care of this for you. "register" as a keyword is basically obsolete and has been for years. Likewise a good compiler will use registers for loop counters etc, automatically.
Lawrence
unless you require dictating which register is what variable to keep consistency between compilers when needing to deal with such details
at that time you are completely on your own
I am yet to get any help clarifying just such a problem where "relying on the compilers intelligence" breaks the design due to inconsistent state
as I need 24 registers to retain state and not lose it by restoring the contents on function exit or pushing it onto the stack at entry
and this is for one of my existing projects
any suggestions? as I need to perform the above *inside* a C wrapper that is not a single function 「at least 282 seperate entry points sharing this set of state 」 and no it's not a design flaw
I would like to make it work on Amiga OS 4 and MorphOS if possible
Flags, I belive –O0 disables optimization, while –Os optimize for size, the higher optimization lever the higher chance the code generated will not work as expected, it should also be possible to disable optimization for one specific function like the code below.
/* disable optimization for this function */ void my_function(void) __attribute__((optimize(0)));
void my_function(void) { /* ... */ }
(NutsAboutAmiga)
Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
There is command called objdump you can investigate, it can be useful to disassemble C code to see how it’s generated,
You might also Allocate executable memory using AllocVecTags(), fill it up whit your generated code.
There is lots of documentation about PowerPC assembler language and macros on the net; I think I have pointed you in direction you need to investigate to produce your Compiler/VM/JIT or whatever you’re trying to make.
Edited by LiveForIt on 2012/9/24 19:24:02
(NutsAboutAmiga)
Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
And for 64 bit on a 32 bit CPU/compiler: typedef struct {int32 hi,lo;} int64;
? :)
Next: the official syntax for 32+64bit AOS4 apps is??? ;)
- Kimmo --------------------------PowerPC-Advantage------------------------ "PowerPC Operating Systems can use a microkernel architecture with all it�s advantages yet without the cost of slow context switches." - N. Blachford