home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!destroyer!cs.ubc.ca!bcsystems!cconstantine
- From: cconstantine@galaxy.gov.bc.ca
- Newsgroups: comp.sys.mac.programmer
- Subject: Variable Wierdness!!!! Help!!!!
- Message-ID: <1993Jan8.193209.1486@galaxy.gov.bc.ca>
- Date: 8 Jan 93 19:32:09 -0800
- Organization: BC Systems Corporation
- Lines: 82
-
- I have a really bizzar problem with some database code I am writing. One of
- the fields in the standard FoxBase/dBase header is the Number of Records in the
- Database. This field is 4-Bytes (LONG right!!) So I look at this field and see
- a rather LARGE negative number (something like -23453568476).
-
- A friend of mine at work suggested swaping the bits around, ie: take the low
- and move it to high and visa-versa.
-
- OK, Now when I look at the high and low Words of this field in different
- variables, they both change after taking the appropriate word out.
-
- Here is the header structure and the ReadDBF function I have written:
-
-
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
- typedef struct
- {
- char valid;
- char date[3]; /* Don't forget this is zero based!! */
- long numRecs;
- short numHead;
- short numPerRec;
- short res1;
- char flag;
- char encrypted;
- long net[3];
- char prodFlag;
- char res2[3];
- } dbfHeader, *dbfPtr, **dbfHandle;
-
-
- void ReadDBF( void )
- {
-
- short fRef,lcount,hcount;
- long count,ltest;
- Handle testBuf;
- dbfHandle testDBF;
- OSErr errCode;
-
- errCode = FSOpen("\pDevelop HD:MPW:AR DataLogger:3test.dbf", 0, &fRef);
- if (errCode) /* Error getting the file */
- DeathAlert( errOpenFile );
-
- /* try getting to the actual Field data */
- testBuf = NewHandle( sizeof( dbfHandle ) );
- if (testBuf == 0) /* Error allocating Memory */
- DeathAlert( errNoMem );
- count = sizeof( dbfHandle );
-
- HLock( testBuf ); /* better safe than sorry */
- errCode = FSRead( fRef, &count, *testBuf );
- if (errCode)
- DeathAlert( errCantRead );
- testDBF = (dbfHandle)testBuf;
- ltest = (**testDBF).numRecs;
- HUnlock( testBuf );
-
- /* testDBF = (dbfHandle)testBuf; */
- FSClose( fRef );
- lcount=LoWrd( ltest ); // These are macros defined for effeciency
- hcount=HiWrd( ltest ); // yes, they are declared properly because
- // Apples' HiWord and LoWord do the same thing
-
- }
- Some of this code come directly from THINK Reference. Anyway, When I look at
- the lcount and hcount variables in SourceBug 1.0.1 each variable changes to
- what the other one is after the line has been executed. This is the most
- bizzare thing I have seen!!!!! Is this a bug with MPW C 3.2.4 or my
- program????????
-
- I have tried various arragnements of my code and the same thing still happens.
- I have also tried using Apples HiWord & LoWord routines, but the same thing
- happens.
-
- Please help!!!
-
-
- Carl B. Constantine
- CCONSTANTINE@galaxy.gov.bc.ca
-