www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/10/20:30:53

From: glynis AT butterfly DOT hjs DOT com (John M. Flinchbaugh)
Newsgroups: comp.os.msdos.djgpp,comp.programming,comp.unix.programmer,comp.os.msdos.programmer
Subject: quickbasic record to c struct?
Date: 9 Dec 1996 04:07:31 -0500
Organization: Happy John Software
Lines: 85
Message-ID: <58gksj$ign@butterfly.hjs.com>
Reply-To: glynis AT netrax DOT net
NNTP-Posting-Host: ns2.netrax.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

i have the following quickbasic 4.5 structure that i use for records in
a file:
---
TYPE Calendar
    Year AS INTEGER
    Month AS STRING * 1
    Day AS STRING * 1
END TYPE
TYPE Time
    Hr AS STRING * 1
    Min AS STRING * 1
END TYPE
TYPE Sheet
    Num AS INTEGER
    DateOut AS Calendar
    TimeOut AS Time
    DateIn AS Calendar
    TimeIn AS Time
    Area AS STRING * 1
    Locat AS STRING * 35
    Nature AS STRING * 1
    AidStatus AS STRING * 1
    Dist AS STRING * 1
    Damage AS LONG
    Personnel AS STRING * 1
    Trucks AS STRING * 1
    Deaths AS STRING * 1
    Mutual AS INTEGER
    Notes AS STRING * 56
    Attend AS STRING * 100
END TYPE
---

and i've coded it as this for gcc (2.7.2) under linux (intel):
---
typedef struct cal_s {
	short int year;
	char month;
	char day;
} cal_t;

typedef struct tim_s {
	char hr;
	char min;
} tim_t;

typedef struct sheet_s {
	short int num;
	cal_t dateout;
	tim_t timeout;
	cal_t datein;
	tim_t timein;
	char area;
	char loc[35];
	char nature;
	char aidststus;
	char dist;
	long int damage;
	char personnel;
	char trucks;
	char deaths;
	short int mutual;
	char notes[56];
	char attend[100];
} sheet_t;
---
my problem is that my c program says that the size of that record is
224 bytes, while the quickbasic program is using it as a 218-byte
record.  obviously, this won't due if the c program is to read the files
written by the old quickbasic program.

i suspect it has something to do with going from 16-bit dos to 32-bit
linux and the data alignment involved in storing records.

what is the easiest way to correct this problem in the c program, for
the data files have already been written, and i need to read them from c
for conversion?  i can't seem to find an option to gcc to allow me to
adjust the alignment.

thank you.
-- 
____________________}John Flinchbaugh{______________________
| -> glynis AT netrax DOT net <-   jmf89784 AT marauder DOT millersv DOT edu |
| http://www.netrax.net/~glynis   jmflinch AT cs DOT millersv DOT edu |
~~~~~~~~~~~~microsoftfree==100%linux==100%power~~~~~~~~~~~~~

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019