Sizes of Integer Types

B

Bob Timpkinson

Hi,

I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits

Thanks!

Bob.
 
J

jacob navia

Bob said:
Hi,

I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits

Thanks!

Bob.

No way unless:
1) You download the source code of gcc
2) Change quite a few things inside

You would have to work for approx 6 months to 2 years depending
on your luck and knowledge about compilers

Just as a gcc user I see no way to do that.

But why you want that in the first place?
 
K

Keith Thompson

Bob Timpkinson said:
I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits

We don't know. Try asking in gnu.gcc.help.
 
M

Mark McIntyre

Hi,

I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits

Why would you want to?
Compilers are built to match the hardware / software environment
they're targetting.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
B

Bob Timpkinson

I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?

It seems logical to me to give every integer size its own type, and then
you can program with confidence knowing how big each variable will be.

Bob.
 
J

jacob navia

Bob said:
I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?

It seems logical to me to give every integer size its own type, and then
you can program with confidence knowing how big each variable will be.

Bob.

I repeat:
There is NO C compiler that allows you to change the sizes of the
basic types. Period.

Please show me one C compiler that does that.

jacob
 
B

Ben Pfaff

Bob Timpkinson said:
I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits

gnu.gcc.help is a better place for this kind of question.
Followups set.

<OFF-TOPIC>
I don't think so. In particular, I don't think GCC has support
for quad-word 128-bit arithmetic, except for use with
processor-specific built-in functions for e.g. SSE support.
</OFF-TOPIC>
 
F

Flash Gordon

jacob navia wrote, On 05/09/07 20:17:
I repeat:
There is NO C compiler that allows you to change the sizes of the
basic types. Period.

Please show me one C compiler that does that.

gcc 3.3.3
-m96bit-long-double/-m128-bit-long-double
-m32/-m64

Or then there are some of the old 80x86 compilers that allowed you to
select one of a number of sies for pointers.

Of course, you cannot select any values you want, and you can't select
what the OP wanted, but you *can* change them between allowed values.
 
W

Walter Roberson

I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?

No, they seldom do. Once you get beyond the arithmetic capabilities
supported by the hardware, operations such as 128 addition or
division must be synthesized in software. In order for a compiler
to allow you to set the type sizes arbitrarily high and support
all the usual arithmetic upon the types, it would have to know how
to generate software integral and floating point operations at
arbitrarily high precisions.

If you are going to support software operations at arbitrarily high
precisions, then instead of expecting the compiler to handle it, it is
usually better to use one of the several indefinite precision
arithemetic packages that are available. You can get packages that
will, for example, support (5**1000 - 4**1000) / 3**1000
and give you the result to (say) 317 decimal places if that's
what you want. Or to 800 decimal places, whatever you ask for
(and that fits into memory). Or which will return the result
as a rational number if that's what you prefer. This work has
been done already.
 
J

jacob navia

Flash said:
jacob navia wrote, On 05/09/07 20:17:

gcc 3.3.3
-m96bit-long-double/-m128-bit-long-double
-m32/-m64

Or then there are some of the old 80x86 compilers that allowed you to
select one of a number of sies for pointers.

Of course, you cannot select any values you want, and you can't select
what the OP wanted, but you *can* change them between allowed values.

This is a completely different thing and you know it.
 
K

Keith Thompson

jacob navia said:
I repeat:
There is NO C compiler that allows you to change the sizes of the
basic types. Period.

Please show me one C compiler that does that.

You really should stop and think for a moment before making sweeping
statements like that.

Here's the source file "c.c" that I use for all three tests:
#include <stdio.h>
int main(void)
{
printf("sizeof(long) = %d\n", (int)sizeof(long));
return 0;
}

On SPARC Solaris 9:
================================
% cc -V
cc: Sun C 5.5 Patch 112760-18 2005/06/14
usage: cc [ options] files. Use 'cc -flags' for details
% cc c.c -o c && ./c
sizeof(long) = 4
% cc -xtarget=ultra -xarch=v9 c.c -o c && ./c
sizeof(long) = 8
================================

On Fedora x86-64:
================================
% gcc --version | head -1
gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)
% gcc -m32 c.c -o c && ./c
sizeof(long) = 4
% gcc -m64 c.c -o c && ./c
sizeof(long) = 8
================================

On AIX PowerPC:
================================
% xlc -qversion
IBM XL C/C++ Enterprise Edition V8.0 for AIX
Version: 08.00.0000.0011
% xlc -q32 c.c -o c && ./c
sizeof(long) = 4
% xlc -q64 c.c -o c && ./c
sizeof(long) = 8
================================

I don't know of any compilers that allow you to specify the sizes of
*all* the predefined integer types.
 
F

Flash Gordon

jacob navia wrote, On 05/09/07 20:43:
This is a completely different thing and you know it.

It is changing the sizes of basic types, something you said was
categorically not provided by any compiler. It is doing it without
switching to a different platform or OS. If you state something as an
absolute, you should expect people to call you on it.

For another processor gcc has the option to make int 16 bits. For yet
another you can select whether int is 32 or 64 bits.

The simple fact is that you were wrong to say that no compilers allow
you to change the size of basic types, and even more wrong to be so
emphatic about it, because some do for some targets.
 
K

Keith Thompson

jacob navia said:
This is a completely different thing and you know it.

It's different from what you probably meant. It's exactly the same as
what you said:

There is NO C compiler that allows you to change the sizes of the
basic types. Period.
 
R

Richard Tobin

Bob Timpkinson said:
I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?
It seems logical to me to give every integer size its own type, and then
you can program with confidence knowing how big each variable will be.

And how are you going to call the system libraries, which assume the
usual sizes? You can probably rebuild gcc to use different sizes, but
doing it on the fly is not worth it.

It would be easier to typedef all your integer types in terms of n-bit
types, or if you really want to you could use macros and define them
on the command line.

-- Richard
 
M

Mark McIntyre

I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?

Why?
It seems logical to me to give every integer size its own type,

You'd better add in 7,9,18,36 and the other bitsizes then, there's
_lots_ of integer sizes out there in the wide world.....
and then
you can program with confidence knowing how big each variable will be.

For a given implementation, you /do/ know. If you're writing code that
really really depends on the sizes, you probably either have an
algorithm error, or you're doing something hardware specific anyway.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
G

Gordon Burditt

I don't believe that's true - surely any C compiler worth its salt will
allow you to set this sort of option?

Surely not (although some compilers give you a limited choice with
"memory models"). Can you imagine the number of different C libraries
you would need for all the possible different combinations of data
type sizes?
It seems logical to me to give every integer size its own type, and then
you can program with confidence knowing how big each variable will be.

It seems logical to me that you cannot know what version of what compiler
will be used by someone else to compile the code.

There are a number of people who "know" (incorrectly) things like
sizeof(int) == sizeof(int *), sizeof(int) == sizeof(long), and
sizeof(int) == 4.
 
E

Eric Sosman

jacob said:
I repeat:
There is NO C compiler that allows you to change the sizes of the
basic types. Period.

Please show me one C compiler that does that.

Sun Studio 12. Also 11, 10, 9, and their Forte forbears.
 
K

karthikbalaguru

jacob said:
No way unless:
1) You download the source code of gcc
2) Change quite a few things inside

Interesting stuff. :) I have the source code of gcc.
What are the things that can possibly be changed to acheive this ?
Let me know your ideas . I have thought of giving that a try :):)

Thx in advans,
Karthik Balaguru
 
K

Keith Thompson

karthikbalaguru said:
Interesting stuff. :) I have the source code of gcc.
What are the things that can possibly be changed to acheive this ?
Let me know your ideas . I have thought of giving that a try :):)

You'll get more and better information in gnu.gcc.help.

But first, consider why you want to do this, and whether another
approach might meet your needs.

If you just want integer types of specified sizes, take a look at the
<stdint.h> header, which defines int8_t, int16_t, etc.
 
K

Kelsey Bjarnason

[snips]

If you just want integer types of specified sizes, take a look at the
<stdint.h> header, which defines int8_t, int16_t, etc.

My copy of the draft says that intN_t types are optional, an
implementation is not required to provide them. As such, it strikes me
that code cannot rely on them unless one gives up portability across
compilers, never mind OSen.

Has this changed, or is this still little more than a good way to
guarantee you're stuck using one vendor's compiler for the rest of
eternity?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top