home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!sunic!dkuug!imada!adelt
- From: adelt@imada.ou.dk (Adel Shavandi)
- Subject: packing/unpacking unsigned in char ?
- Message-ID: <1992Nov15.225151.7502@imada.ou.dk>
- Summary: packing/unpacking unsigned in char ?
- Keywords: packing/unpacking unsigned in char
- Sender: news@imada.ou.dk (USENET News System)
- Organization: Dept. of Math. & Computer Science, Odense University, Denmark
- Date: Sun, 15 Nov 1992 22:51:51 GMT
- Lines: 47
-
-
-
- I need some suggestions for an effective and correct way to
- pack/unpack unsigneds in [0,127] in chars and communicate
- them to another process.
-
- What i do myself is as the following code:
-
-
- // child process:
- // ...
- unsigned num1;
- // ...
- // num1 is in [0,127] now
- printf("%c",num1); // later is rediercted to parent by pipe mech.
- // ...
-
-
- // parent process:
- // ...
- unsigned num2;
- char ch;
- int n=read (fd,&ch,1);
- if (n>0)
- num2=(unsigned) ch;
- // ...
-
-
- Now i know this may be wrong since sometimes i receive some wrong
- numbers. Any ideas/suggestions ?
-
- But what is interesting is that the wrong numbers are very similiar
- each time. Am i confronting with pitfalls ?!
-
-
-
-
-
- Hope somebody have some good ideas/suggestions.
-
-
-
-
- Regards,
-
- Ade'l
-
-