Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* 32 and 64 bit questions
@ 1999-11-04  5:00 Larry W Loen
  1999-11-05  5:00 ` Robert Harley
  1999-11-15  5:00 ` 32 and 64 bit questions (some results) Larry W Loen
  0 siblings, 2 replies; 7+ messages in thread
From: Larry W Loen @ 1999-11-04  5:00 UTC (permalink / raw)


As you can tell by the company I work for, I don't
have much to do professionally with DEC systems.

But, I am a bit puzzled at some things I read and
have been told over the years about Alpha and
C/C++.

Particularly, exactly how elementary C scalars are 
"sizeof-ed" on DEC C/C++ compilers.

I was once told that the C construct "long" was
supposed to be 64 bits for Alpha, but reading
about the DEC C and DEC C++ compiler manuals on-line
more or less contradicts it.

For instance, the max and min for long are 32 bits
in limits.h for both C and C++ books.  That
says long is "always" 32 bits.

There's lots of talk in the C
manual about __intial_pointer_size and nothing
about long as other than 32 bits.

Yet, the __32BIT macro variable in the C++ manual selects
a mode where "long and pointer are both 32 bits"
(implying, perhaps, that long is 64 bits on Alpha).
There is a section about getting your data types right
which states pretty openly that long can be 64 bits
at least some of the time.  Yet, it also states
min and max consistent with 32 bits near as I can
tell.

I know things like int64 and int32 are available
via includes and so on, but what I want to know
is if something like this is accurate:

                  sizeof
Compiler    int   long    void*    Notes
DEC C        4     4      4 or 8   4 when __32BIT 
DEC C++ VMS  4   4 or 8   4 or 8   4 and 4 when __32BIT
                                   8 and 8 otherwise
DEC C++ Unix 4     4      4        __32BIT is defined??

(where DEC C++ Unix means "the target is Unix").

Will a compile targeting Unix always define __32BIT?

BTW, do VAX compiles always set __32BIT now for C/C++?

Are the long LONGMIN and LONGMAX set right if long is allowed
to be 64 bits?

I am guestimating that predefined macro variables are:

DEC C   __intitial_pointer_size 
     defined when 64 bit pointers possible
     undefined when __32BITS is defined

DEC C++  __32BITS when long and void* always 64 bits.
         C++ does not seem to allow any 32 and 64 mixed 
         mode where pointers can be sometimes 32 and
         other times 64.
         
and that I would do something like:

#ifdef __DECCXX_VER
 #ifdef __ALPHA  /* meaning VMS and not Unix */
  #ifdef __32BITS
     #define SIZEOFLONG 4
     #define SIZEOFVOIDSTAR 4
  #else
     #define SIZEOFLONG 8
     #define SIZEOFVOIDSTAR 8
  #endif /* __32BITS */ 
 #else
     #define SIZEOFLONG 4
     #define SIZEOFVOIDSTAR 4
 #endif  /* __ALPHA */
#endif   /* DEC C */

#ifdef __DECC_VER
 #define SIZEOFLONG 4
 #ifdef __initial_pointer_size
    #define SIZEOFVOIDSTAR __initial_pointer_size
 #else
    #define SIZEOFVOIDSTAR 4
 #endif /* __initial_pointer_size */
#endif /* DEC C++ */

to find out about the sizes of any particular
environment my code found itself in.

BTW, what rules does GNU for Alpha follow?

Disclaimer:  I certainly don't want any 
proprietary stories on this, just a 
simple explanation of how things are.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions
  1999-11-04  5:00 32 and 64 bit questions Larry W Loen
@ 1999-11-05  5:00 ` Robert Harley
  1999-11-06  5:00   ` Larry Loen
  1999-11-15  5:00 ` 32 and 64 bit questions (some results) Larry W Loen
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Harley @ 1999-11-05  5:00 UTC (permalink / raw)



Larry W Loen <lwloen@rchland.vnet.ibm.com> writes:
> I was once told that the C construct "long" was
> supposed to be 64 bits for Alpha, but reading
> about the DEC C and DEC C++ compiler manuals on-line
> more or less contradicts it.

Longs are 64 bits on Linux and Tru64 Unix, but 32 bits on VMS and
WinNT.  I suspect they're 64 on BSD but I'm not certain.

Rob.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions
  1999-11-05  5:00 ` Robert Harley
@ 1999-11-06  5:00   ` Larry Loen
  1999-11-09  5:00     ` bdwheele
  1999-11-09  5:00     ` Jeff Donsbach
  0 siblings, 2 replies; 7+ messages in thread
From: Larry Loen @ 1999-11-06  5:00 UTC (permalink / raw)
  To: Robert Harley

Robert Harley wrote:

> Larry W Loen <lwloen@rchland.vnet.ibm.com> writes:
> > I was once told that the C construct "long" was
> > supposed to be 64 bits for Alpha, but reading
> > about the DEC C and DEC C++ compiler manuals on-line
> > more or less contradicts it.
>
> Longs are 64 bits on Linux and Tru64 Unix, but 32 bits on VMS and
> WinNT.  I suspect they're 64 on BSD but I'm not certain.
>
> Rob.

Thanks for the reply.  It's helpful, but not
enough for this poor fellow who has no
machine available to settle it.

There is a kind of incestual relationship between
and operating system and a compiler.

At the end of the day, however, the operating system
really does not determine what "sizeof(int)" or
"sizeof(long)" is.  The compiler does.

An OS may write its documentation "as if" it controlled
these things.  That means an OS interface may be
written with sizeof(int) and sizeof(long) _presumed_
to be certain values, but the compiler, in the end,
controls what is actually done.  To be sure, the
compiler has some good incentive to mimic the
OS' rules, but it may or may not actually do so.

Thus, the OS document can say
that a given input value on a given interface
is a "long" and mean "64 bit signed integer." But
the compiler only need supply _some_ way
of generating a 64 bit integer.  It may define long
as 32 and use either long long or something like
__int64 for 64 bit binary numbers.  I've seen it done.

And, while the OS may happen to provide a compiler
along with it that expresses its presumptions about what
"sizeof(long)" should be, there are usually alternative compilers
as well that may or may not have different rules.  For
instance, if most of my application was independent of
the OS, and was first written for NT, I might use an
Alpha-targeting Microsoft C/C++ or maybe a variant
of GNU C created with MS conventions for all but the
modules in my application that deal directly with the OS.

Thus, my interest is really not just the OS rules, but
how the compilers _implement_ them and what flags
they turn on to indicate which rules are active.

I'm very interested in what DEC C and C++ define
and how they define them (e.g. what/when __32BITS
is active and what OS flags and so on go with such
a setting).  I'm also a bit interested in MS C++ and
GNU, but the DEC/COMPAQ are my first
interest.

So far as I can tell, the DEC C and C++ (and their
COMPAQ-branded upgrades) seem to have different
rules.  At best, the on-line documentation is inconsistent
and unclear on long.

Still, I think I get some good answers from your
note.  I think I should expect the following:

                                int      long      void*
Microsoft C/C++      4         4          8      ****
DEC C/C++             4         8          8      **
GNU                        4         8          8      ** ***

** Unless running in __32BITS mode.  Assumed
        same for 64 bit VMS and Tru64.
*** I'm assuming that if Alpha Linux has a
       64 bit long, it has a 64 bit void*
***** Since MS C++ only supported NT conventions

but the DEC/COMPAQ documentation doesn't
unambiguously support the above table nor provide
a consistent way for telling what is what between
its C and C++.  Or, so I read it.

Can you help me further?







^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions
  1999-11-06  5:00   ` Larry Loen
@ 1999-11-09  5:00     ` bdwheele
  1999-11-09  5:00     ` Jeff Donsbach
  1 sibling, 0 replies; 7+ messages in thread
From: bdwheele @ 1999-11-09  5:00 UTC (permalink / raw)


In article <3824F582.855F31FA@rchland.vnet.ibm.com>,
	Larry Loen <lwloen@rchland.vnet.ibm.com> writes:
> Robert Harley wrote:
> 
>> Larry W Loen <lwloen@rchland.vnet.ibm.com> writes:
>> > I was once told that the C construct "long" was
>> > supposed to be 64 bits for Alpha, but reading
>> > about the DEC C and DEC C++ compiler manuals on-line
>> > more or less contradicts it.
>>
>> Longs are 64 bits on Linux and Tru64 Unix, but 32 bits on VMS and
>> WinNT.  I suspect they're 64 on BSD but I'm not certain.
>>
>> Rob.
> 
> Thanks for the reply.  It's helpful, but not
> enough for this poor fellow who has no
> machine available to settle it.
> 
> There is a kind of incestual relationship between
> and operating system and a compiler.

Well, sort of...since they're both children of the same parents...

> 
> At the end of the day, however, the operating system
> really does not determine what "sizeof(int)" or
> "sizeof(long)" is.  The compiler does.

That is true, but it is more complex than that.  There's nothing to
say that a long on a 64-bit machine _can't_ be 32 bits.  When an
OS is being created, it is defined in terms of the compiler that's
building it.  If a long is defined as 32 bits by the compiler, then
a long will be 32 bits to the OS, and similarly for a 64 bit long.


> 
> An OS may write its documentation "as if" it controlled
> these things.  That means an OS interface may be
> written with sizeof(int) and sizeof(long) _presumed_
> to be certain values, but the compiler, in the end,
> controls what is actually done.  To be sure, the
> compiler has some good incentive to mimic the
> OS' rules, but it may or may not actually do so.

The OS uses the compiler's rules, since the compiler exists first...usually
as a cross compiler.  Since they're defined by the same people, we can
assume that the compiler is designed to handled the data types/sizes that
the OS designers want for defining their OS...

> 
> Thus, the OS document can say
> that a given input value on a given interface
> is a "long" and mean "64 bit signed integer." But
> the compiler only need supply _some_ way
> of generating a 64 bit integer.  It may define long
> as 32 and use either long long or something like
> __int64 for 64 bit binary numbers.  I've seen it done.
> 
> And, while the OS may happen to provide a compiler
> along with it that expresses its presumptions about what
> "sizeof(long)" should be, there are usually alternative compilers
> as well that may or may not have different rules.  For
> instance, if most of my application was independent of
> the OS, and was first written for NT, I might use an
> Alpha-targeting Microsoft C/C++ or maybe a variant
> of GNU C created with MS conventions for all but the
> modules in my application that deal directly with the OS.

These compilers mimic the 32/64 bit rules of the original compiler, in order
to use the headers and libraries supplied by the OS (which, were generated
by the original compiler)


> 
> Thus, my interest is really not just the OS rules, but
> how the compilers _implement_ them and what flags
> they turn on to indicate which rules are active.
> 
> I'm very interested in what DEC C and C++ define
> and how they define them (e.g. what/when __32BITS
> is active and what OS flags and so on go with such
> a setting).  I'm also a bit interested in MS C++ and
> GNU, but the DEC/COMPAQ are my first
> interest.
> 
> So far as I can tell, the DEC C and C++ (and their
> COMPAQ-branded upgrades) seem to have different
> rules.  At best, the on-line documentation is inconsistent
> and unclear on long.
> 
> Still, I think I get some good answers from your
> note.  I think I should expect the following:
> 
>                                 int      long      void*
> Microsoft C/C++      4         4          8      ****
> DEC C/C++             4         8          8      **
> GNU                        4         8          8      ** ***
> 
> ** Unless running in __32BITS mode.  Assumed
>         same for 64 bit VMS and Tru64.
> *** I'm assuming that if Alpha Linux has a
>        64 bit long, it has a 64 bit void*
> ***** Since MS C++ only supported NT conventions
> 
> but the DEC/COMPAQ documentation doesn't
> unambiguously support the above table nor provide
> a consistent way for telling what is what between
> its C and C++.  Or, so I read it.

void* is going to be funny under NT.  NT is really using only 32 bits 
for addressing, regardless of platform, so it is safe (in theory) to
store a void* in an int on NT, but a bad idea to do it on anything else.

Brian Wheeler
bdwheele@indiana.edu







^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions
  1999-11-06  5:00   ` Larry Loen
  1999-11-09  5:00     ` bdwheele
@ 1999-11-09  5:00     ` Jeff Donsbach
  1999-11-11  5:00       ` Larry Loen
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff Donsbach @ 1999-11-09  5:00 UTC (permalink / raw)


Roberts answer is 100% correct. On Tru64 Unix, "long" is always 64 bit and
"int" is always 32 bit using Compaq compilers. Other compilers such as gcc
COULD use different rules, but I believe don't. That would be inconsistent
with the system API's that expect "long" to be 64 bit values. Section 2.2 of
the Tru64 Unix Programmer's Guide defines the sizes of all the base data
types for Tru64 Unix. This applies to both C and C++. The FORTRAN compilers
allow you to control the default size of the "INTEGER" data type via
compiler switches. Seems pretty unambiguous to me.

What is this "__32BITS" macro you are talking about? I've never seen it. Is
it in some #include file you've found somewhere, perhaps the Rogue Wave
include files that come with the C++ compiler? The Compaq compilers do not
recognize any such #define that would alter the size of "long" data types.
It is not possible to change the size of "long" data types with Compaq C or
C++ compilers. I can't speak for other compilers.

By the way - in MS VC++ for Alpha, "void *" is also only 4 bytes, same as
x86,  as Windows NT is a 32 bit operating system and all pointers are always
32 bits (leaving the Win64 SDK out of the picture for simplicity's sake).

Is that any clearer now?

Jeff D






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions
  1999-11-09  5:00     ` Jeff Donsbach
@ 1999-11-11  5:00       ` Larry Loen
  0 siblings, 0 replies; 7+ messages in thread
From: Larry Loen @ 1999-11-11  5:00 UTC (permalink / raw)
  To: Jeff Donsbach



Jeff Donsbach wrote:

> Roberts answer is 100% correct. On Tru64 Unix, "long" is always 64 bit and
> "int" is always 32 bit using Compaq compilers. Other compilers such as gcc
> COULD use different rules, but I believe don't. That would be inconsistent
> with the system API's that expect "long" to be 64 bit values. Section 2.2 of
> the Tru64 Unix Programmer's Guide defines the sizes of all the base data
> types for Tru64 Unix. This applies to both C and C++. The FORTRAN compilers
> allow you to control the default size of the "INTEGER" data type via
> compiler switches. Seems pretty unambiguous to me.
>

Yes, I'm getting to understand this.  You have to realize, however,
that I had been going strictly by documentation I blundered into on-line
when I posted my original message.

I'm increasingly suspicious, thanks to responses like yours,
that the story is as I was originally told verbally:

  sizeof(int) is 4 bytes
  sizeof(long) is 8 bytes
  sizeof(void*) is usually 8 bytes.

is the correct one and that "usually" is true by default
(see below for a bit more).

>
> What is this "__32BITS" macro you are talking about? I've never seen it. Is
> it in some #include file you've found somewhere, perhaps the Rogue Wave
> include files that come with the C++ compiler? The Compaq compilers do not
> recognize any such #define that would alter the size of "long" data types.
> It is not possible to change the size of "long" data types with Compaq C or
> C++ compilers. I can't speak for other compilers.
>

In this aforementioned documentation I've blundered into, there seems to
be compile modes you can set that ask for a 32 bit data model.  When you set
that mode, the compiler sets a predefined variable __32BITS.  This must be
some kind of accommodation for old 32 bit apps or maybe it has
something to do with dealing with some old VAX support.  I have
no real idea.

So, if __32BITS is defined, it is a _compiler_ predefined macro based
on your asking for a 32 bit pointer/data model.

Both the older DEC C++ and newer COMPAQ C++ manuals I've
found on line seem to mention it.  It may be that Tru64 doesn't happen
to support this variation for all I know.


>
> By the way - in MS VC++ for Alpha, "void *" is also only 4 bytes, same as
> x86,  as Windows NT is a 32 bit operating system and all pointers are always
> 32 bits (leaving the Win64 SDK out of the picture for simplicity's sake).
>
> Is that any clearer now?
>
> Jeff D

Yes, this is all coming clear now.  Thanks.  Nothing like
a real domain expert to get answers.

I've also had some excellent help from
an individual via private e-mail.  I'd like
to acknowledge that person by name, but since that person
hasn't posted here, I'll merely state my thanks to a "knowledgable
source" until I get some kind of permission.  I forgot
to ask.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 32 and 64 bit questions (some results)
  1999-11-04  5:00 32 and 64 bit questions Larry W Loen
  1999-11-05  5:00 ` Robert Harley
@ 1999-11-15  5:00 ` Larry W Loen
  1 sibling, 0 replies; 7+ messages in thread
From: Larry W Loen @ 1999-11-15  5:00 UTC (permalink / raw)
  To: Hal Murray

I am happy to acknowledge the contributions
to my little quest from Hall Murray of
DEC/COMPAQ and to further confirm the 
postings of Robert Harley and Jeff 
Donsbach on the various options supported
by DEC Alpha systems and their C/C++ 
compilers.

A simple little program, run by Hal,
produced the following results.

Note that the results
assume a fixed width font and that
"#define" means the compiler 
predefines the macro variable
and "#undef" means the compiler
does not predefine the macro variable.

Note also that the GNU results may
not be 100% standard.  GNU's macro
variables are controlled by whomever
did the port.  These results may be universal
across the DEC COMPAQ world or it may
not.  I have GNUs available to me that
put a single underscore before the 
CPU architecture name.  

However, it does look like __alpha 
can be relied upon very universally.


       #define   #undef
GNU
 C                 
     __alpha
     __alpha__
      __GNUC__
                __32BITS
                __initial_pointer_size
GNU
C++
   __cplusplus
       __alpha
     __alpha__
      __GNUC__
                __32BITS
                __initial_pointer_size

DEC 
 C
      __alpha
      __ALPHA
   __DECC_VER
                __32BITS
                __initial_pointer_size

DEC
C++
(unavailable)

In all cases, sizeof(int)==4 bytes
    sizeof(long)== 8 bytes
 and sizeof(void*) is the natural size.

I realize this is breathtakingly
obvious to some folks, but remember
that I all had was inconsisent (and
some of it old/obsolete??) documentation.
Or, maybe I just can't read ;-).

Only DEC C seems to support a
"-taso_short" option for a 32 bit
address space at all and its only known
effect is to set sizeof(void*) to
4.  Long remains at 8 bytes in
all known cases.

None of the "known" macro
variables relating to 32 versus
64 seem to be set by any of
the compilers.  By "known" I
mean "seen in an on-line manual
I tracked down with Northern
Lights search engine."

Perhaps those few hardies who
want a 32 bit application memory
space are expected to pass in some 
-D value of their own devising on 
their make files that passs in the
-taso_short option?  



The program used to produce these results
is as follows:



------- compdebug.c or compdebug.cpp
#include <stdio.h>

int main() {

  printf("sizeof(int) %d ",((sizeof(int))));
  printf("sizeof(long) %d sizeof(void*) %d\n",
    (sizeof(long)),
    (sizeof(void*)));

#ifdef __cplusplus
  printf("__cplusplus\n");
#endif

#ifdef __alpha
  printf("__alpha\n");
#endif

#ifdef __alpha__
  printf("__alpha__\n");
#endif


#ifdef _alpha
  printf("_alpha\n");
#endif

#ifdef __ALPHA
  printf("__ALPHA\n");
#endif

#ifdef __ALPHA__
  printf("__ALPHA__\n");
#endif


#ifdef __DECC_VER
  printf("__DECC_VER %d\n",
    __DECC_VER);
#endif

#ifdef __DECCXX_VER
  printf("__DECCXX_VER %d\n",
     __DECCXX_VER);
#endif

#ifdef __GNUC__
  printf("__GNUC__\n");
#endif

#ifdef __initial_pointer_size
  printf("__initial_pointer_size %d\n",
      __initial_pointer_size);
#endif

#ifdef __32BITS
  printf("__32BITS\n");
#endif

 return 0;

}
------- end compdebug.c or .cpp



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1999-11-15  5:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-11-04  5:00 32 and 64 bit questions Larry W Loen
1999-11-05  5:00 ` Robert Harley
1999-11-06  5:00   ` Larry Loen
1999-11-09  5:00     ` bdwheele
1999-11-09  5:00     ` Jeff Donsbach
1999-11-11  5:00       ` Larry Loen
1999-11-15  5:00 ` 32 and 64 bit questions (some results) Larry W Loen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox