HPUX and Compaq problem-urgent

Thread Tools Search this Thread
Top Forums Programming HPUX and Compaq problem-urgent
# 1  
Old 05-14-2002
Java HPUX and Compaq problem-urgent

Hi All
Following is the lines of code which simply makes a structure of 1 bit member and 7 bit is unused.Then the structure is initialised with char pointer.The output on HPUX(BIG Endian) and Compaq(Little Endian) are different.On HPUX it gives zero and Compaq it gives 1. I never thought that the bit reading/writing within a byte will be different.Can U help me in understanding this behaviour.

I am looking at Endian issue on two platforms.

#include <stdio.h>


struct single_t{
unsigned int sh:1;
unsigned int unused:7;

struct single_t single,*ptr;

char ch=(char)1;

ptr=(struct single_t *)&ch;
printf("\nValue from C is %d",ptr->sh);

# 2  
Old 05-14-2002
It is not legal to cast a pointer to char to be a pointer to a structure and then dereference it. When you break rules like that you get non-portable code. If you want your code to be portable, it's this easy: obey the rules.

As to understanding the behavior, the c standard does not specify which bits get allocated first with bit fields. The two compiler writers chose different paths.
# 3  
Old 05-14-2002
Hi perderabo
The previuos "c" code was for just testing the machine behaviour.Actually the problem is as follows:
I am getting data on X.25 line which is read into a structure of following type-
struct track_number_t{
unsigned int sb:3;
unsigned int sttn:1;
unsigned int STR:12;
I am wondering what changes I will have to do so that the present Compaq running code should work on HPUX also. The above format refers to one type in ASTERIX 030 format used in eurocontrol standards.

I had written another code in which I have reversed the structure members delacration order on HPUX.After doing reverse I get the same output as on Compaq.Original code is in Ada and I am trying to simulate things in C for finding a solution.

#include <iostream>

struct track_number_t{
unsigned int sb:3;
unsigned int sttn:1;
unsigned int STR:12;
struct rev_track_number_t{
unsigned int STR:12;
unsigned int sttn:1;
unsigned int sb:3;
track_number_t track_number,*track_ptr;
//char *str="A8";
char *str="AA";
track_ptr = (track_number_t *)str;
std::cout << "Value of sb is "<< track_ptr->sb;
std::cout << std::endl << "value of sttn is "<< track_ptr->sttn;
std::cout<< std::endl<< "Value of STR is "<< track_ptr->STR;

//Steps on reversed struct
rev_track_number_t rev_track_number,*rev_track_ptr;
rev_track_ptr = (rev_track_number_t *)str;
std::cout<<std::endl<<"Printing reversed struct memebrs";
std::cout << "Value of sb is "<< rev_track_ptr->sb;
std::cout << std::endl << "value of sttn is "<< rev_track_ptr->sttn;
std::cout<< std::endl<< "Value of STR is "<< rev_track_ptr->STR;


Hope to hear from you soon.

Last edited by Shobhit; 05-14-2002 at 02:52 PM..
# 4  
Old 05-14-2002
Originally posted by Shobhit
Hi perderabo

track_ptr = (track_number_t *)str;

Hope to hear from you soon.
You are still dereferencing a pointer after an illegal promotion. That is still illegal. And on an HP, you're risking a segmentation fault.

But the larger issue is that you are assuming that the internal layout of a structure is portable. It's not. Reversing the order of elements may indeed solve the problem of moving from compaq to hp. But you have traded one non-portable program for another. Next time, you may need to port to another box that leaves a gap between bit-fields. What then?
# 5  
Old 05-14-2002
That was real quick :-)
Here are few more clarifications from my side
1)I am using chararcter or char array to simulate memory. As I said before that the data is coming from external line and I will be reading memory and assinging values to my structure members. (This I guess happens in any communication...wild guess).
2) As the communication is in octets i again presume that the octets coming one after another will be stored in consecutive locations and then assinged to local variables.

3)internal layout of a structure is portable. It's not
layout is standarderised and I am trying to allign my structure according to the standard.

4)To be concise if i can have a clear picture of what all happens when I transfer the single structure(using X.25 and not transfering it directly..just to make myself clear to u) from compaq to Hp system. Assume the structure I mentioned before. Now as the standard aslo demands the members should have same value on the two systems. for the same reason I am declaring my structures on compaq and hp differently so that in the end the members have same value.

Thanks a lot for ur time...can i request some more time from U :-)
# 6  
Old 05-14-2002
1) You actually are dumping a collection of bits into a structure and then you are using the individual members. If you would do what you actually said in paragraph one, there would be no problem. Breaking the data up as it arrives and storing it into the individual members is the way to go.

2) I would hope so Smilie

3) I know. You're hardly alone. But the practice still saddens me. I'll get over it.

4) You would be better off to stop thinking like that. You don't transfer a structure from one system to another. You tranfer a collection of data that might be called a frame, or a packet, or a cell, or a datagram. The data might be stored in structures at both ends. But the data comes out of the structure and is used to assemble a packet. The packet arrives at the other end. The data gets broken up and stored back into a similiar structure. I know, you want the packet to be the structure. I know it looks attractive to do that. I know it looks like it saves a lot of effort. But this why you're having trouble now.

Suppose, for a minute, that c had nothing called a structure. How would you write the code then? For the most part, that is what you should do. That would force you to code the algorithms correctly. Then go back and use structures only to organize collections of variables. That is all that structures are intended to do.
# 7  
Old 05-14-2002
At this time I would like to clear myself of few more communications doubt..elaborating on ur 4th reply only for the present one...
I have to send following information to some application

unsigned int sb:3;
unsigned int sttn:1;
unsigned int STR:12;

forming a packet or frame may mean formaing an array of bytes and sending it.I guess this is what a data-packet may mean.Later on OS will hadd header and tail and form packet to gogogogo......
So ultimately my data is in form of array of bytes. Am i right..I doubt?

Anyways I have to transfer above information. I discuss two ways which are purely my theoritical assumption as i have not worked on communication protocol stacks or same before....
1)I will simply read sb and sttn as one byte char and STR as 2 single byte char.This will make an array of 4 bytes for me.This data frame i shall simply pass on to OS to send via network.singles bytes may be reassembled properly at other end but problems arise for STR being sent as 2 singlt byte chars.Which byte will be sent first?How the two bytes will be stored relatively?How it will be read at other end? So i see problems..

2)Other way is ..combine them into a structure as follows
struct track_number_t{
unsigned int sb:3;
unsigned int sttn:1;
unsigned int STR:12;

and send the bytes as chars or octets as is said in communication world. Here again the issue arises of which byte is transmitted first and how it is read.

Now when U say structures are not transmitted across network then what are the headers..eg TCP-IP header has address fields,packet number fields,check sum and bla bla ...I agree that at applicaion level we don't have to worry about headers and all but these are also programmed by some programmers which may not be called application programmer...how do they take care of endian issues...any idea.

Next i shall reply after 6 hours of sleep. I remember long bakc also U tried ur best to explain TCP-IP transmission to me but some how that is still not clear to me and the more I think I get confused.....

you shall hear from me after I get up :-)

Thanks a lot for ur patience...discussions on other points if any later...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Problem in Configuring kerberos Server on HPUX

Hi, I am getting this error during kerberos server setup in HPUX 11.31 : kdb_create: unknown LDAP backend error while adding master entry to the database ps -ef|grep ldap root 3905 1 0 13:11:36 ? 0:00 /opt/ldapux/bin/ldapclientd Unable to find out the meaning of this... (1 Reply)
Discussion started by: Amit Kulkarni
1 Replies

2. HP-UX

hpux-itanium 64 bit problem for libC

i am trying to build on hpux-itanium 64 bit platform. my application needs to link to 64 bit version of the library libCsup.so This library is present in /usr/lib/hpux64/libCsup.so I am specifying the location of this library as linker flags LDFLAGS := -Wl,-N -Wl,+s... (0 Replies)
Discussion started by: skyineyes
0 Replies

3. HP-UX

pwage-hpux-T for Trusted HPUX servers

I'm sharing this in case anybody needs it. Modified from the original solaris pwage script. This modified hpux script will check /etc/password file on hpux trusted systems search /tcb and grep the required u_succhg field. Calculate days to expiry and notify users via email. original solaris... (2 Replies)
Discussion started by: sparcguy
2 Replies

4. HP-UX

Having problem with mounting in HPUX

Hi Gurus, I'm using HP-UX B.11.23 system. I've been having some problem in mounting a filesystem that has been defined in /etc/fstab as shown below. fstab entries: /dev/vgsap/ora10264 /oracle/PRD/102_64 vxfs rw,suid,nolargefiles,delaylog,datainlog 0 2 /dev/vgsap/orasapreog... (2 Replies)
Discussion started by: superHonda123
2 Replies

5. Shell Programming and Scripting

Need Script to Use CPUs on a HPUX server to simulate Workload Manager on HPUX.

I am running HPUX and using WLM (workload manager). I want to write a script to fork CPUs to basically take CPUs from other servers to show that the communication is working and CPU licensing is working. Basically, I want to build a script that will use up CPU on a server. Any ideas? (2 Replies)
Discussion started by: cpolikowsky
2 Replies

6. HP-UX

Problem with HPUX as NIS-Client

Hi all! I am running an NIS Server with Linux. Now I want to configure a HPUX-Server to use this NIS Server. I have don all the configuration stuff exactly as described in the documentation. When I run YPWHICH, it shows me the right server and domain. If I run YPCAT passwd, I'll get the... (4 Replies)
Discussion started by: pepade
4 Replies

7. Filesystems, Disks and Memory

HPUX 10.20 and RAID ARENA EX3 shutdown problem

Hello, I am having a Problem with an Arena EX3 Raid on an HPUX 10.20 Workstation. Everything is working fine until I shutdown the Server and power off the Raid. Then I get a filesystem corruption on the Raid. This happens everytime. The Raid is configured as Raid Level 1. I would really... (1 Reply)
Discussion started by: nleuenbe
1 Replies

8. HP-UX

HPUX Login Problem on the console

Hi Everyone, I have an HP3000 server on which I am unable to login to the server.I connected the server to my laptop thru a serial cable and I am unable to login thru any user ..when i enter my login id ..the system gets me back to the login prompt without asking me for a password. Cud u pls... (1 Reply)
Discussion started by: hunk
1 Replies

9. UNIX for Dummies Questions & Answers

URGENT : fsck in HPUX

Experts!!! I have an urgent solution for a problem with the HP Unix workstation. I am not able to check the file system for a particular volume. when i tried with $> fsck -o full /dev/vg00/rlvol9 Returns.. full file system check required... exiting... $> How do i recover the... (4 Replies)
Discussion started by: anent
4 Replies

10. UNIX for Dummies Questions & Answers

Oracle problem with HPUX 11.0

HI all I think i can get a perfect solution for our problem here. we r using oracle 7i on hpux 11.0 as a billing server .The thing is it used to get hanged sometime and we need to unmount and need to mount the oracle DB then we need to start the oracle process.The process running in that... (6 Replies)
Discussion started by: edwin_francis
6 Replies
Login or Register to Ask a Question