home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16332 < prev    next >
Encoding:
Text File  |  1992-11-15  |  1.3 KB  |  60 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!sunic!dkuug!imada!adelt
  3. From: adelt@imada.ou.dk (Adel Shavandi)
  4. Subject: packing/unpacking unsigned in char ?
  5. Message-ID: <1992Nov15.225151.7502@imada.ou.dk>
  6. Summary: packing/unpacking unsigned in char ?
  7. Keywords: packing/unpacking unsigned in char
  8. Sender: news@imada.ou.dk (USENET News System)
  9. Organization: Dept. of Math. & Computer Science, Odense University, Denmark
  10. Date: Sun, 15 Nov 1992 22:51:51 GMT
  11. Lines: 47
  12.  
  13.  
  14.  
  15. I need some suggestions for an effective and correct way to
  16. pack/unpack unsigneds in [0,127] in chars and communicate
  17. them to another process.  
  18.  
  19. What i do myself is as the following code:
  20.  
  21.  
  22. // child process:
  23.     // ...
  24.     unsigned num1;
  25.     // ...
  26.     // num1 is in [0,127] now
  27.     printf("%c",num1); // later is rediercted to parent by pipe mech.
  28.     // ...
  29.  
  30.  
  31. // parent process:
  32.     // ...
  33.     unsigned num2;
  34.     char ch;
  35.     int n=read (fd,&ch,1);
  36.     if (n>0)
  37.         num2=(unsigned) ch;
  38.     // ...
  39.  
  40.  
  41. Now i know this may be wrong since sometimes i receive some wrong
  42. numbers. Any ideas/suggestions ?
  43.  
  44. But what is interesting is that the wrong numbers are very similiar
  45. each time. Am i confronting with pitfalls ?! 
  46.  
  47.  
  48.  
  49.  
  50.  
  51. Hope somebody have some good ideas/suggestions.
  52.  
  53.  
  54.  
  55.  
  56.             Regards,
  57.  
  58.                 Ade'l
  59.  
  60.