473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

porting issues ?

Hi,
Can somone please describe the problems one would face when we try
to port a software written in C to another platform some of them being
endianness ,alignment,data types etc ?

It would be very helpful if you could state the solution along with
problem .Also can you please give me some pointers and links to
documents so that porting can be easily accomplished ?

Navin
-
Nov 13 '05 #1
19 3433

"navin_2016" <na********@yahoo.co.in> schrieb im Newsbeitrag
news:26**************************@posting.google.c om...
Hi,
Can somone please describe the problems one would face when we try
to port a software written in C to another platform some of them being
endianness ,alignment,data types etc ?
There should be no problem as long as you strictly adhere to the C standard
(which is seldom possible).
If you put nonstandard stuff into separate compilation units, porting will
at least be easier than if you mix standard and nonstandard things
everywhere.
It would be very helpful if you could state the solution along with
problem .Also can you please give me some pointers and links to
documents so that porting can be easily accomplished ?

Navin
-

Nov 13 '05 #2
navin_2016 wrote:

Can somone please describe the problems one would face when we
try to port a software written in C to another platform some of
them being endianness ,alignment,data types etc ?


If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #3
CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #4
nrk
Kevin Goodsell wrote:
CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?

-Kevin


One problem that comes to mind is reading/writing using fread/fwrite
(structs, ints, floats etc.)...

-nrk.
Nov 13 '05 #5
Kevin Goodsell wrote:

CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?


For starters, see Question 20.5 in the comp.lang.c
Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

.... and don't forget to follow the links you'll find there.

--
Er*********@sun.com
Nov 13 '05 #6
nrk wrote:
Kevin Goodsell wrote:

CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?

-Kevin

One problem that comes to mind is reading/writing using fread/fwrite
(structs, ints, floats etc.)...


Yes, but neither Chuck nor I would do that.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #7
Kevin Goodsell wrote:
CBFalconer wrote:
If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?


For example, endianness, sizeof various entities, value of
CHAR_BIT, etc.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #8
CBFalconer wrote:
Kevin Goodsell wrote:

Could you explain what specific problems you are referring to with
respect to binary files?

For example, endianness, sizeof various entities, value of
CHAR_BIT, etc.


The only one of those that seems like a serious problem to me is
CHAR_BIT. Byte-order and the number of bytes for a given field would be
determined by the file format, which must be agreed upon by both sides
regardless of whether it's text or binary.

But, if the source and destination machine use different byte-sizes, I'm
not sure what you'd do, partly because I don't know how the file would
be translated. Obviously a file with 9-bit bytes moved to a machine with
8-bit bytes needs to be converted somehow. Suppose the conversion
consists of throwing away the high-order bit for each byte. In that
case, you just make sure you don't use that bit - limit yourself to the
8-bit range for each byte.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 14 '05 #9
On Mon, 08 Dec 2003 23:19:16 GMT, CBFalconer <cb********@yahoo.com>
wrote in comp.lang.c:
Kevin Goodsell wrote:
CBFalconer wrote:
If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?


For example, endianness, sizeof various entities, value of
CHAR_BIT, etc.


I'm curious, Chuck, because I know you're a long time embedded systems
programmer with experience on many different architectures, as I am.

Have you ever worked on a platform where CHAR_BIT was NOT 8? I've
done some Analog Devices SHARC work where CHAR_BIT was 32, and I'm
doing a lot of work on a TI 2812 DSP right now where CHAR_BIT is 16.

If you have worked on platforms where CHAR_BIT was greater than 8,
have they always had signed and unsigned char having the same
representation as signed and unsigned int (if not also signed and
unsigned long)?

Note that many standard functions, particularly all FILE * streams,
are impossible to implement on a platform where UCHAR_MAX == UINT_MAX,
since all file input if built on fgetc(), which can return any
unsigned character value from 0 to UCHAR_MAX, and EOF which must be a
negative integer and have a recognizably different bit pattern from
the above.

As for dealing with data internally on platforms with CHAR_BIT > 8,
it's not really all that hard. All the code in my chapter of C
Unleashed is "CHAR_BIT > 8" safe, because you only use the 8 least
significant bits an unsigned char and ignore anything else.

In the real world, I recently wrote both ends of a parser/formatter
for a proprietary CAN bus protocol. CAN messages (as you probably
know, but others might not) contain between 0 and 64 bits of data,
packed into 0 to 8 octets of 8 bits each.

My parser and formatter can pack and unpack various 8, 16, and 32 bit
values from any possible starting point in the data field of such a
packet into a signed or unsigned 8, 16, or 32 bit data object.

Since the processor on one side of the protocol was a TI DSP with
CHAR_BIT 16, it was written with "CHAR_BIT > 8" portability in mind.
The resultant source code compiles and runs properly both on the DSP
and on the other end of the CAN bus, where the ARM processor does have
8 bit character types.

There is only one tiny bit of surplus code to achieve that
portability. At one point there is an expression where an unsigned
char value is updated like this:

uc = (uc << 2) & 0xff;

....the mask is unnecessary when CHAR_BIT is 8 but is necessary on the
DSP because other parts of the code require all bits above 8 in the
unsigned char (if any) always be 0.

The value of CHAR_BIT is not much of a deterrent to portable code if
you give it a little thought and avoid using more than 8 of them even
when they are available.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #10
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<2A*****************@newsread2.news.pas.earth link.net>...
CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?

-Kevin


I am trying to learn this thing. This is a hypothetical situtation.
I want to read an APPLE disk raw mode connected to an intel processor.
What are the issues that has to be handled.

Navin
-
Nov 14 '05 #11
Jack Klein wrote:
.... snip ...
I'm curious, Chuck, because I know you're a long time embedded systems
programmer with experience on many different architectures, as I am.

Have you ever worked on a platform where CHAR_BIT was NOT 8? I've
done some Analog Devices SHARC work where CHAR_BIT was 32, and I'm
doing a lot of work on a TI 2812 DSP right now where CHAR_BIT is 16.
.... snip ...
The value of CHAR_BIT is not much of a deterrent to portable code if
you give it a little thought and avoid using more than 8 of them even
when they are available.


No, I haven't actually run into the problem. But I see no reason
to ignore it (not that I am suggesting you do).

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #12
Kevin Goodsell wrote:
But, if the source and destination machine use different
byte-sizes, I'm not sure what you'd do, partly because I don't
know how the file would be translated. Obviously a file with
9-bit bytes moved to a machine with 8-bit bytes needs to be
converted somehow.


Can somebody name one or more processors manufactured in 2003 where
CHAR_BIT is *not* a power of 2?

Nov 14 '05 #13
On 8 Dec 2003 21:05:56 -0800
na********@yahoo.co.in (navin_2016) wrote:
Kevin Goodsell <us*********************@neverbox.com> wrote in message
news:<2A*****************@newsread2.news.pas.earth link.net>...
CBFalconer wrote:
If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.


Could you explain what specific problems you are referring to with
respect to binary files?


I am trying to learn this thing. This is a hypothetical situtation.
I want to read an APPLE disk raw mode connected to an intel processor.
What are the issues that has to be handled.


Raw disk access is a separate topic from binary file access. The
standard defines ways of handling binary files, but does not define ANY
way of doing raw disk access.

<OT>
In practical terms, it is completely impossible to read some disks on an
x86 platform with a typical BIOS unless you talk directly to the disk
controller. Even then, disks from some systems will be completely
unreadable as they use a different low level format. So you would need
to work out exactly what you want to do and ask somewhere else.
</OT>
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
Nov 14 '05 #14
In <Kr*****************@newsread1.news.pas.earthlink. net> Kevin Goodsell <us*********************@neverbox.com> writes:
nrk wrote:
Kevin Goodsell wrote:
CBFalconer wrote:

If you adhere to the C standard, you should have no problems with
any of those, barring the use of binary files created or used by
other systems. That you can avoid by using text.

Could you explain what specific problems you are referring to with
respect to binary files?

-Kevin


One problem that comes to mind is reading/writing using fread/fwrite
(structs, ints, floats etc.)...


Yes, but neither Chuck nor I would do that.


That's highly irrelevant. The user has done that and you must write a
program to process his data.

And there are perfectly good reasons for writing binary files this
way, especially when size does matter. Just document the format of
each binary item in the file.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #15
In <rR*****************@newsread2.news.pas.earthlink. net> Kevin Goodsell <us*********************@neverbox.com> writes:
CBFalconer wrote:
Kevin Goodsell wrote:

Could you explain what specific problems you are referring to with
respect to binary files?

For example, endianness, sizeof various entities, value of
CHAR_BIT, etc.


The only one of those that seems like a serious problem to me is
CHAR_BIT.


There was only one known platform with a conforming hosted
implementation having CHAR_BIT != 8. If portability to real world
hosted implementations is a concern, CHAR_BIT is the last thing I would
worry about.

The most important one is probably the very limited I/O capabilities
provided by standard C that effectively force people to use platform
specific extensions for both functionality and security related reasons.

As we all know, even something as trivial as suppressing terminal echo
or checking the availability of input in stdin are insoluble problems in
standard C.
Byte-order and the number of bytes for a given field would be
determined by the file format, which must be agreed upon by both sides
regardless of whether it's text or binary.


If it's text, all you have to agree upon is a field separator and
optionally a maximum field length (useful to detect garbage input).
And a character set, of course :-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #16
In <br**********@news-rocq.inria.fr> Grumble <in*****@kma.eu.org> writes:
Kevin Goodsell wrote:
But, if the source and destination machine use different
byte-sizes, I'm not sure what you'd do, partly because I don't
know how the file would be translated. Obviously a file with
9-bit bytes moved to a machine with 8-bit bytes needs to be
converted somehow.


Can somebody name one or more processors manufactured in 2003 where
CHAR_BIT is *not* a power of 2?


Do a Google search for "24-bit dsp". But the important thing is that
there are no hosted implementations for such processors.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #17
In <26**************************@posting.google.com > na********@yahoo.co.in (navin_2016) writes:
I am trying to learn this thing. This is a hypothetical situtation.
I want to read an APPLE disk raw mode connected to an intel processor.
What are the issues that has to be handled.


Everything related to transferring the bytes from the disk to the memory.

Once you have the bytes in memory, you can process them with portable C
code (if you know what to do with them).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #18
Da*****@cern.ch (Dan Pop) writes:
[...]
There was only one known platform with a conforming hosted
implementation having CHAR_BIT != 8. If portability to real world
hosted implementations is a concern, CHAR_BIT is the last thing I would
worry about.


Really? What platform is it? (I presume you're not talking about the
DS9000.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 14 '05 #19
In <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
Da*****@cern.ch (Dan Pop) writes:
[...]
There was only one known platform with a conforming hosted
implementation having CHAR_BIT != 8. If portability to real world
hosted implementations is a concern, CHAR_BIT is the last thing I would
worry about.


Really? What platform is it? (I presume you're not talking about the
DS9000.)


The C89 implementation for the Univac 1100 (or something like that) had
9-bit char's and it was also (in)famous for using one's complement
arithmetic.

Such characteristics were not exactly uncommon once upon a time, but this
is the only such hardware platform with a C89 implementation that I'm
aware of.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #20

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

Similar topics

2
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more...
2
by: Anand | last post by:
Hi Are there any tools that would help in porting code from Pyton 2.3 to 2.4 ? I have gone through the whatsnew documents and created a document comparing Python 2.4 to 2.3. But so far has not...
7
by: Sonny | last post by:
I need to port a library that is written entirely in C to C++. The library is supported on quite a few platforms (windows, Solaris, Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing...
4
by: golu | last post by:
Has any body done the porting from oracle to sql server, what were the issues in porting the data bases? Also suggest some resources which can be helpful in the porting project TIA Golu
0
by: Raymond L. Buvel | last post by:
I am preparing to release an extension module that interfaces Python to the Class Library for Numbers (http://www.ginac.de/CLN/). This module will provide Python types for arbitrary precision...
16
by: Mohanasundaram | last post by:
Hi All, We are working on porting a product written in C and C++ from 32 bit to 64 bit. We need to maintain both 32 bit and 64 bit versions in the future. We took the 32 bit source code and...
1
by: Massimo Mannelli | last post by:
I know it is a 10 years old question, but I need to know if there are some issues, procedures, websites, people that have already done the porting from a borland 4.0 to the Microsoft Visual...
5
by: BK-Chicago | last post by:
I am in the midst of porting a massive MFC application from VS6.0 to VS8.0. While i have fixed most of the compile time errors, i do have quite a linker error that i have not been able to resolve....
5
by: shobhah | last post by:
Hi, We have a complete succsssfully working product on 32bit sparc solaris machine for which compiler used is CC 5.8 Now we are migarting our product from 32 bit to 64bit sparc solaris machine....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.