Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
116 user(s) are online (94 user(s) are browsing Forums)

Members: 0
Guests: 116

more...

Support us!

Headlines

 
  Register To Post  

(1) 2 »
Integer in source code
Just popping in
Just popping in


See User information
If its in the docs I missed it.

If using 'int' instead of 'int8' (16,32,or 64) what size 'int' is used?

Seems like it should be 8.

A1-X1000
Go to top
Re: Integer in source code
Just can't stay away
Just can't stay away


See User information
@mechanic

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".

Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
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.

Why stop it now, just when I am hating it?

Thore Böckelmann
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Thanks guys.

It was just one of those questions that seemed to come from ...... wherever????

A1-X1000
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
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.
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Quote:

LiveForIt wrote:
int8 is what we call a "char"
int16 is what we call a "short".

16bit unsigned hex number 0xFFFF is not -1, but a signed 16bit hex number 0xFFFF is -1.


That makes sense, gotta put the sign someplace.

Thanks

A1-X1000
Go to top
Re: Integer in source code
Amigans Defender
Amigans Defender


See User information
As already mentioned, the size of "int" and other C types are defined by the compiler implementation. See the ISO C standard for complete details.

Note that the default sign of the type may also be defined by the compiler implementation.

I'm working with an embedded compiler that has "int" defaulting to unsigned and it is 16 bits wide.

It has nothing to do with being "modern" but rather everything to do with the target platform.

ExecSG Team Lead
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
Default for most c compilers are signed (GCC,VBCC), where as the unsigned variables has to declared.

Int y; // signed variable
Unsigned int x; // unsigned

Anyway it better to use int32 and uint32 if you wont to port you program to different operating systems, if not then I don't think it matters.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Okay.
So lets say for X1000 and one of the Sam boards (your choice).

Does using smaller values offer any efficiency, other than moving bits down a pipe?

(talking platform only)

A1-X1000
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
http://stackoverflow.com/questions/22 ... as-loop-counter-variables

In general for "average" or indistinct integer vales, use int as it matches the width of machine registers.

Lawrence

Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Quote:

Aslak3 wrote:
http://stackoverflow.com/questions/22 ... as-loop-counter-variables

In general for "average" or indistinct integer vales, use int as it matches the width of machine registers.

Lawrence

Generally speaking then, it looks like not much has changed in 30+ years.
The size considerations mostly apply to memory usage and serial lines/lanes.

Er,,,,Generally.

A1-X1000
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
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.
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
Way is this important:


int cnt;

For (cnt=0;cnt<10;cnt++) {
}

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.
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Quote:

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

Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
Quote:

Aslak3 wrote:
Quote:

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

Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
At least whit GCC you can set optimizing level.

-Os
-O0
-O1
-O2

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.
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
Belxjander you might by pass it all by inline assembler and macros.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Integer in source code
Just popping in
Just popping in


See User information
the caller and callee are compiled separately along with some sections of the called routines replaced by code from other compilers

so all the entry points have to comply without any wrapper due to being direct accessible functions from outside callers

as it is the documentation for GCC in this case is a known incomplete section with regards to explaining the use of as within GCC

Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
@Belxjander

http://developer.gnome.org/anjuta-bui ... /stable/build-gcc.html.en

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.
Go to top
Re: Integer in source code
Not too shy to talk
Not too shy to talk


See User information
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
Go to top

  Register To Post
(1) 2 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project