home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13408 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.9 KB  |  59 lines

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!uwm.edu!bionet!turbo.bio.net!will
  2. From: will@turbo.bio.net (Will Nelson)
  3. Newsgroups: comp.lang.c
  4. Subject: sizeof()
  5. Message-ID: <Sep.9.14.38.29.1992.10548@turbo.bio.net>
  6. Date: 9 Sep 92 21:38:29 GMT
  7. Organization: GenBank Computing Resource for Mol. Biology
  8. Lines: 49
  9.  
  10. I've run into an incompatibility between Microsoft C 7.0
  11. and the unbundled ANSI C compiler (1.1) of SUN Microsystems.
  12.  
  13. The deal is that the input file is a series of structs
  14. that were written with fwrite on the DOS system. When I
  15. fread the structs on the program compiled with Microsoft C
  16. 7.0 on DOS, they get read correctly. When I fread the structs
  17. using the program compiled with SUN's acc on UNIX, the fread's
  18. do not fill the buffer correctly. I have tracked it down
  19. to a difference in what the sizeof() operator returns.
  20.  
  21. Here is the struct:
  22.  
  23. extern struct Feature_Form Feature_Form_Buffer;
  24.  
  25. struct Location {
  26.   char base_position[7];
  27.   int  operator_token;
  28. };
  29.  
  30. struct Feature_Form {
  31.   char ain_label[3];  /* 1 or 2 letter unique identifier for feature */
  32.   char feature_key[16]; 
  33.   char user_defined_feature_label[16];  
  34.   char complement;      /* flag set if complement chosen from format */
  35.   struct Location Start_Location;
  36.   struct Location End_Location;
  37. };
  38.  
  39.  
  40. The fread's are done like this:
  41.  
  42.   while (fread(&Feature_Form_Buffer, sizeof(Feature_Form_Buffer), 1, mainfptr) =
  43. = 1) {
  44.  
  45.  
  46. If I look at what sizeof(Feature_Form_Buffer) produces, it comes out
  47. as 56 on the DOS side and 60 on the UNIX side.
  48.  
  49. Needless to say, this looks like a show-stopper.
  50. I've given up on trying to determine which is the "Correct" behavior,
  51. mainly because I don't have the ANSI C standards document.
  52. What I want to know is, is there any way to get the UNIX acc compiler
  53. to give the same result as the DOS compiler? I would like to use
  54. the same code in both environments if at all possible.
  55. -- 
  56. Will Nelson
  57. Systems Programmer, IntelliGenetics, Inc.
  58. will@presto.ig.com
  59.