Re: porting problems encountered
From: RC Bryan (rcbryan_at_hotmail.com)
Date: 12/09/03
- Next message: Tom Linden: "RE: SEARCH enhancement"
- Previous message: Graham Burley: "Re: SEARCH enhancement"
- In reply to: navin_2016: "porting problems encountered"
- Next in thread: navin_2016: "Re: porting problems encountered"
- Reply: navin_2016: "Re: porting problems encountered"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Dec 2003 15:56:37 -0800
If you have a simple application that does simple stuff, it is simple
to take it from one computer and run it on another.
If you are passing binary structured data over the network between
computers of different types, you can be guaranteed that you will have
trouble of one sort or another.
Programs that only move data between variables of the same types
generally do OK. Enabling all warnings on for your compiler and making
the source code compile clean on both machines, is a step in the right
direction.
When you see casting, it is an indication that something may be up.
More specific:
Tru64 compiles long variables to size 8 bytes while VMS and HP-UX
compiles them to 4 bytes (long long is required for 64 bit variables.)
If you do something underbright like:
struct MYSTRUCT
{
short sval;
long val;
short sval2;
long val2;
} mystruct, mystruct2;
Some compilers will fill in after sval and s2val with unnamed elements
to force the val and val2 elements to the proper boundaries. The size
of this structure is either 16 or 32 bytes, depending upon the size of
long (32 or 64 bits). It seems like if you run this on a 16 bit
platform, the size of the structure would be 12 bytes.
If you were to do something like:
memcpy((void*)&mystruct2, (void*)&mystruct, 16);
you would not get what you want because on Tru64, only the first half
would be initialized. Using:
memcpy((void*)&mystruct2, (void*)&mystruct, sizeof(mystruct2) );
will solve this problem.
Another popular problem is to do pointer manipulation with integer
arithmetic.
I had a case where they wanted a pointer to the beginning of a 16 byte
bounded region. The original code read something like:
char * sub(char *p)
{
int myP=p;
myP = (myP+15)& 0xfffffff0;/* add and mask back down */
p=(char *)myP;
. . .
This will break all kinds of places. On 64 bit platforms, the
pointers are 64 bits while int is 32 bits. It really got interesting
when it got to the AS/400 with 128 bit pointers.
An example of an endian problem:
long value=0x1234567;
sub((short*)&value);
...
void sub(short *val)
{
printf("val=%x", *val);
}
will print out:
val=123 on an HP and Solaris (sparc)
val=4567 on Tru64, VMS and Wintel
val=0 on 64 bit Solaris
We are accessing 16 bits of a 32 or 64 bit value:
0x0000000001234567
An example of a bounding problem:
Using the struct from before:
p=malloc(sizeof(mystruct)*2);
p+=sizeof(int);
intVal=((struct MYSTRUCT*)p)->val; /* val is long*/
This will run with a warning on some platforms, crash on others and
run just fine on others. If your code was sloppy to begin with, you
may be running cases like this without knowing it.
Conclusion:
Basically, if your program only references internal variables by name
and you don't mix types, you will be fine. Another idea is to use one
of those ridiculous languages where you have to stand on your head to
avoid any possibility of having any problems.
This is a lot longer than I had intended.
Pascal said it best, "Forgive the long letter, I didn't have time to
write a short one."
Regards,
/RC Bryan
PS, I think you would be more satisfied with the responses if this
were posted on a C programming type newsgroup rather than VMS.
navin_2013@yahoo.co.in (navin_2016) wrote in message news:<268bf130.0312080455.b31cf9f@posting.google.com>...
> 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
> -
- Next message: Tom Linden: "RE: SEARCH enhancement"
- Previous message: Graham Burley: "Re: SEARCH enhancement"
- In reply to: navin_2016: "porting problems encountered"
- Next in thread: navin_2016: "Re: porting problems encountered"
- Reply: navin_2016: "Re: porting problems encountered"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|