32 bit vs. 64 bit systems

A

alexis

hi,

i am writing a server that may be run from different systems. is
there a way to determine what system (the one currently running the
program) is, programatically? i was thinking about using getconf
WORD_BIT but i'm not sure that is enough. i need to know the bitness
b/c i am sending raw bytes from client to server and need to know how
many bits/int, etc.

also, how do you know if the size of a long is the same as or larger
than an int? does it depend on the system you're on? is there any way
to determine this?

thanks!
 
V

Victor Bazarov

alexis said:
i am writing a server that may be run from different systems.

Is it going to be the same executable or the same source recompiled
on every system?
is
there a way to determine what system (the one currently running the
program) is, programatically?

Not using standard C++ means.
i was thinking about using getconf
WORD_BIT but i'm not sure that is enough.

Your guess is just as good as ours. 'getconf' is not standard.
i need to know the bitness
b/c i am sending raw bytes from client to server and need to know how
many bits/int, etc.

You will have to rely on some kind of system-specific way of handling
data.
also, how do you know if the size of a long is the same as or larger
than an int?

Use 'sizeof'. If sizeof(int) == sizeof(long), they are the same.
Otherwise they aren't.
does it depend on the system you're on?

Yes, it does.
is there any way
to determine this?

Use 'sizeof'.

Victor
 
I

Ioannis Vranos

alexis said:
hi,

i am writing a server that may be run from different systems. is
there a way to determine what system (the one currently running the
program) is, programatically?


I cannot understand what exactly you want to determine.


i was thinking about using getconf
WORD_BIT but i'm not sure that is enough. i need to know the bitness
b/c i am sending raw bytes from client to server and need to know how
many bits/int, etc.


also, how do you know if the size of a long is the same as or larger
than an int?


You can use numeric_limits & sizeof.

does it depend on the system you're on?

Yes.


is there any way
to determine this?


See above.






--
Ioannis

* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
 
D

Dave Rahardja

hi,

i am writing a server that may be run from different systems. is
there a way to determine what system (the one currently running the
program) is, programatically? i was thinking about using getconf
WORD_BIT but i'm not sure that is enough. i need to know the bitness
b/c i am sending raw bytes from client to server and need to know how
many bits/int, etc.

also, how do you know if the size of a long is the same as or larger
than an int? does it depend on the system you're on? is there any way
to determine this?

thanks!

The way that data is sent between the client and the server depends on the
protocol specification, not the language or the bit size of either machine.

Read (or write) the protocol specification first, then think about how you
might implement it on either side of the conduit.

Hint: You may want to define several fixed-width integer types in a
typedef-only header file, then use #ifdef's to bind the typedefs to the
built-in types appropriate to each target platform at compile time.
 
S

Shane Beasley

i am writing a server that may be run from different systems. is
there a way to determine what system (the one currently running the
program) is, programatically? i was thinking about using getconf
WORD_BIT but i'm not sure that is enough. i need to know the bitness
b/c i am sending raw bytes from client to server and need to know how
many bits/int, etc.

There are many more issues than how many bits are in a byte and how
many bytes are in an int. See the Serialization section of the C++
FAQ:

<http://www.parashift.com/c++-faq-lite/serialization.html>

If you're seriously considering binary serialization, I would strongly
suggest looking into using someone else's implementation: XDR-RPC,
DCE-RPC, XML-RPC, DCOM, CORBA, YAMI
(http://www.maciejsobczak.com/prog/yami/)...
also, how do you know if the size of a long is the same as or larger
than an int? does it depend on the system you're on? is there any way
to determine this?

ISO C++ guarantees that long is always at least as big as int; whether
they are the same size depends on the system. You can determine which
is the case by comparing sizeof(int) to sizeof(long).

- Shane
 
I

Ioannis Vranos

Shane Beasley said:
(e-mail address removed) (alexis) wrote in message
ISO C++ guarantees that long is always at least as big as int; whether
they are the same size depends on the system. You can determine which
is the case by comparing sizeof(int) to sizeof(long).


In theory an int and a long could have different sizes and yet store the
same range of values, that could happen if long had additional padding bits
than int.


So if someone wants to check ranges, he had better also use numeric_limits.







--
Ioannis

* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
 
S

Shane Beasley

Ioannis Vranos said:
In theory an int and a long could have different sizes and yet store the
same range of values, that could happen if long had additional padding bits
than int.

If the Standard allows that scenario, then either the Standard needs
to be changed to forbid it, or it ought to be ignored, because it
makes no sense. Why make the type bigger if doing so doesn't increase
the range of the type?

I stand by my original claim: If you want to know whether type X is
bigger than type Y, assert(sizeof(X) > sizeof(Y)) is sufficient.
Whether X is more expressive than Y is another story, but if X and Y
are both integer types, and neither is char, then it *should* follow
that relation of sizeofs is proportional to relation of ranges. (I can
see where there may be padding, but certainly there's no reason to
define an integer type as "the same as another integer type, but with
more padding.")

- Shane
 
P

puppet_sock

If the Standard allows that scenario, then either the Standard needs
to be changed to forbid it, or it ought to be ignored, because it
makes no sense. Why make the type bigger if doing so doesn't increase
the range of the type?

The standard simply does not speak to the issue. How a CPU wields
integers, especially in the case of multiplication, is not something
that is specified. For example, the short and long integer might
both use up a word. But the short might be involved in multiplies
a different way through a co-processor. Or the long might require
those extra padding bits to get carried along for the purposes of
the co-processor during its work, but not be meaningful when the
co-processor was not working. Or words might not be a multiple of
8 bits wide. (I recall a computer that had 60 bit words.) So a
short might be one word (or 16 bits of one word, or 24 or 32).
And a long might be one plus a fraction words, in order that it
come out to 32 bits or 64 bits or whatever.

There are other nasty complications due to things like some CPUs
requiring variables to exist on word boundaries, others not
requiring it. Or sometimes the top bit of a word is a flag that
means something like overflow or parity or some such, but this
can be turned off when you use the word as two variables. And
any of a large number of other possibilities. C++ has been
ported to a lot of pretty whacky hardware.

In any case, the numeric limits info is the correct place to look
for the limits a variable type can hold. This is because the info
in there is supplied by the compiler implementers, and they are
supposed to have properly dealt with all this complication.
Socks
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top