home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21057 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.7 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!destroyer!cs.ubc.ca!bcsystems!cconstantine
  2. From: cconstantine@galaxy.gov.bc.ca
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Variable Wierdness!!!! Help!!!!
  5. Message-ID: <1993Jan8.193209.1486@galaxy.gov.bc.ca>
  6. Date: 8 Jan 93 19:32:09 -0800
  7. Organization: BC Systems Corporation
  8. Lines: 82
  9.  
  10. I have a really bizzar problem with some database code I am writing.  One of
  11. the fields in the standard FoxBase/dBase header is the Number of Records in the
  12. Database.  This field is 4-Bytes (LONG right!!) So I look at this field and see
  13. a rather LARGE negative number (something like -23453568476).
  14.  
  15. A friend of mine at work suggested swaping the bits around, ie: take the low
  16. and move it to high and visa-versa.
  17.  
  18. OK,  Now when I look at the high and low Words of this field in different
  19. variables, they both change after taking the appropriate word out.
  20.  
  21. Here is the header structure and the ReadDBF function I have written:
  22.  
  23.  
  24. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  25. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  26.  
  27. typedef struct
  28. {
  29.     char        valid;
  30.     char        date[3];    /* Don't forget this is zero based!! */
  31.     long        numRecs;
  32.     short        numHead;
  33.     short        numPerRec;
  34.     short        res1;
  35.     char        flag;
  36.     char        encrypted;
  37.     long        net[3];
  38.     char        prodFlag;
  39.     char        res2[3];
  40. } dbfHeader, *dbfPtr, **dbfHandle;
  41.  
  42.  
  43. void ReadDBF( void )
  44. {
  45.  
  46.     short            fRef,lcount,hcount;
  47.     long            count,ltest;
  48.     Handle            testBuf;
  49.     dbfHandle        testDBF;
  50.     OSErr            errCode;
  51.     
  52.     errCode = FSOpen("\pDevelop HD:MPW:AR DataLogger:3test.dbf", 0, &fRef);
  53.     if (errCode)        /* Error getting the file */
  54.         DeathAlert( errOpenFile );
  55.     
  56.     /* try getting to the actual Field data */
  57.     testBuf = NewHandle( sizeof( dbfHandle ) );
  58.     if (testBuf == 0) /* Error allocating Memory */
  59.         DeathAlert( errNoMem );
  60.     count = sizeof( dbfHandle );
  61.     
  62.     HLock( testBuf );        /* better safe than sorry */
  63.     errCode = FSRead( fRef, &count, *testBuf );
  64.     if (errCode)
  65.         DeathAlert( errCantRead );
  66.     testDBF = (dbfHandle)testBuf;
  67.     ltest = (**testDBF).numRecs;
  68.     HUnlock( testBuf );
  69.     
  70. /*    testDBF = (dbfHandle)testBuf; */
  71.     FSClose( fRef );
  72.     lcount=LoWrd( ltest );  // These are macros defined for effeciency
  73.     hcount=HiWrd( ltest );  // yes, they are declared properly because
  74.                 // Apples' HiWord and LoWord do the same thing
  75.     
  76. }
  77. Some of this code come directly from THINK Reference.  Anyway, When I look at
  78. the lcount and hcount variables in SourceBug 1.0.1 each variable changes to
  79. what the other one is after the line has been executed.  This is the most
  80. bizzare thing I have seen!!!!!  Is this a bug with MPW C 3.2.4 or my
  81. program????????
  82.  
  83. I have tried various arragnements of my code and the same thing still happens. 
  84. I have also tried using Apples HiWord & LoWord routines, but the same thing
  85. happens.
  86.  
  87. Please help!!!
  88.  
  89.  
  90. Carl B. Constantine
  91. CCONSTANTINE@galaxy.gov.bc.ca
  92.