473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fixed sized output

How can I perform output (file output for the monent, possibly socket in the
future) in such a way that output produced on different compiler/machines
pairs is indistinguishable? Specifically my concern is over different byte
sizes. If I want to output say 32 bits how do I do that? If one machine has
8-bit chars then 4 of those will do but what happens when the code is run on
say a 9-bit char machine? 4 chars will output 36-bits then. There is some
way to achieve this right? The reason - the output is to be read in Java so
I want to output fixed size data so that I can simply say readInt() (32
bits), readLong() (64 bits) etc. I want binary due to the amount of data and
of course time effeciency is a concern.

Please and thank you.
Jul 19 '05 #1
4 2300
"Ellarco" <no****@eircom.net> wrote...
How can I perform output (file output for the monent, possibly socket in the future) in such a way that output produced on different compiler/machines
pairs is indistinguishable? Specifically my concern is over different byte
sizes. If I want to output say 32 bits how do I do that? If one machine has 8-bit chars then 4 of those will do but what happens when the code is run on say a 9-bit char machine? 4 chars will output 36-bits then. There is some
way to achieve this right? The reason - the output is to be read in Java so I want to output fixed size data so that I can simply say readInt() (32
bits), readLong() (64 bits) etc. I want binary due to the amount of data and of course time effeciency is a concern.


For the binary output to look exactly the same way on several
platforms, you will have to write platform-specific code to convert
your internal data into some form that when written looks the same.

In general binary exchange between systems should be avoided for
this particular reason: incompatibility at the binary level. IOW,
if you want to do it right, use text.

Victor
Jul 19 '05 #2

"Ellarco" <no****@eircom.net> wrote in message
news:%m*******************@news.indigo.ie...
How can I perform output (file output for the monent, possibly socket in the future) in such a way that output produced on different compiler/machines
pairs is indistinguishable? Specifically my concern is over different byte
sizes. If I want to output say 32 bits how do I do that? If one machine has 8-bit chars then 4 of those will do but what happens when the code is run on say a 9-bit char machine?
I think the possibility of a 9 bit char is so remote that you need not worry
about it.
4 chars will output 36-bits then. There is some
way to achieve this right? The reason - the output is to be read in Java so I want to output fixed size data so that I can simply say readInt() (32
bits), readLong() (64 bits) etc. I want binary due to the amount of data and of course time effeciency is a concern.
I doubt that an 8-bit char machine and a 9-bit char machine cound even
communicate with each other without some software between to handle the
transition from 8 bit bytes to 9 bit bytes. What the right thing for you to
do would depend on how that software handled the transition, not something
under your control.

Please and thank you.


john
Jul 19 '05 #3

"Ellarco" <no****@eircom.net> wrote in message
news:di*******************@news.indigo.ie...
Okay, youre not telling me anything I want to hear. Is this not a reasonably common problem? Are there no libraries designed for fixed size, network
order binary output?

Speculate on this if you have a moment. Ill be using the Java Native
Interface (JNI) headers. The JNI defines types that are
<tongue-in-cheek>guaranteed</tongue-in-cheek> to be the same size as Java
primitives. So a jbyte is 8-bits, a jint is 32-bits, etc. For example, on my platform (Wintel) jbyte is typedef'd to a signed char. Do you reckon that if a reputable body (e.g. Sun) has written JNI headers for a particular
platform, that executing code such as

#include <jni.h>
...
jint ji = 10;
...
myOstream << ji;
...

will output 32-bits regardless of that platforms specific/crazy byte sizes? Would it even be possible to define a jbyte (8-bits) on a 9 bit byte machine (I pick 9-bits cos its awkward, not because its likely -- I want my code
very portable, with the aid of the Autotools).

Care to speculate?

Thanks to both for replies.

El.


20 years in the business, I've never come accross a machine that didn't have
8 bit bytes. I think you are just going to have to accept that were you to
come across such a machine your code would not be portable.

john
Jul 19 '05 #4
"John Harrison" <jo*************@hotmail.com> wrote...

"Ellarco" <no****@eircom.net> wrote in message
news:di*******************@news.indigo.ie...
Okay, youre not telling me anything I want to hear. Is this not a reasonably
common problem? Are there no libraries designed for fixed size, network
order binary output?

Speculate on this if you have a moment. Ill be using the Java Native
Interface (JNI) headers. The JNI defines types that are
<tongue-in-cheek>guaranteed</tongue-in-cheek> to be the same size as Java primitives. So a jbyte is 8-bits, a jint is 32-bits, etc. For example,

on my
platform (Wintel) jbyte is typedef'd to a signed char. Do you reckon
that if
a reputable body (e.g. Sun) has written JNI headers for a particular
platform, that executing code such as

#include <jni.h>
...
jint ji = 10;
...
myOstream << ji;
...

will output 32-bits regardless of that platforms specific/crazy byte sizes?
Would it even be possible to define a jbyte (8-bits) on a 9 bit byte

machine
(I pick 9-bits cos its awkward, not because its likely -- I want my code
very portable, with the aid of the Autotools).

Care to speculate?

Thanks to both for replies.

El.


20 years in the business, I've never come accross a machine that didn't

have 8 bit bytes. I think you are just going to have to accept that were you to
come across such a machine your code would not be portable.


I think that since Ellarco's problem is stemming from Java, and
since Java is a platform, the problem is platform-specific and
cannot be answered in terms of standard C++. Just MHO.

Victor
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
179
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
98
by: Pamel | last post by:
I know this must have been asked elsewhere, but I cannot find it. There is a piece of text on my web page that I don't want browsers to resize. IE won't resize it if I specify the size in px, but...
10
by: Justin Barrett | last post by:
Hi I'm currently doing a project in my free time. One problem I ran into is that things like short, int, and long all have different meanings as to size on different platforms. In this program...
11
by: Linny | last post by:
Hi, I need some help in declaring an array of pointers to array of a certain fixed size. I want the pointers to point to arrays of fixed size only (should not work for variable sized arrays of the...
1
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using...
4
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this text data into a string. I've got it working just fine, but I have to put the text data into into a...
3
by: kaffekopp | last post by:
Hi, Since this is the first time for me using fixed size arrays, i would appreciate some guidance to solve this question. First of all, these structures are to be used: struct song { char ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.