Solved

Maintaining 16 bit data alignment in Win32 platform

Posted on 1998-07-09
8
252 Views
Last Modified: 2010-04-15
Is there a way to maintain the 16 bit data alignment in win32 platform.  We have a Borland C program compiled in 16 bit platform that we recompiled into 32bit dll.  The dll accesses a binary file with 16 bit data alignment.  How could we do this correctly since we usually make use of the sizeof function?
0
Comment
Question by:borgz
8 Comments
 
LVL 11

Expert Comment

by:alexo
Comment Utility
There are several solutions.

1) Add a compiler switch to pack data on 2 byte boundaries.
2) Add a #pragma before the code to the same effect.
3) Add a couple of #pragma's around critical data structures to the same effect.

Unfortunately, I don't have the Borland compiler in front of me but MS compiler uses the "/Zp2" compiler switch or "#pragma pack(2)".  Check the compiler documentation.
0
 

Author Comment

by:borgz
Comment Utility
For example we have this data structure:
typedef struct {
 char Tword[50];
 TCategory Category;
} TMeaning;

typedef struct {
 char Word[20];
 TMeaning Meaning[20];
} TElement;

These are the very data structure that I am using for the so called binary file that was created using 16 bit (actually in Turbo C ver 2.0) compiler. Granting that we are going to use functions compiled in win32 platform that will access this binary file having the previous data alignment, how do we add the #pragma directive?
0
 

Author Comment

by:borgz
Comment Utility
Could someone help us with this fast?

alexo, do you know the equivalent of #pragma pack(2) in Borland C compiler?
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
I don't think there is a pragma for this in the Borland compiler but there is a command line switch.  Sorry, I don't hremember what it is and I don't have a copy of BC++ anymore.  You should be able to get a listing of the command line options by typing the TC/BC (or whatever it is) command with no options.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Accepted Solution

by:
abesoft earned 70 total points
Comment Utility
From the command-line it's -a2.
In BC4.51, you can use the menu to choose Options|Project|32-bit Compiler|Processor, and choose "Word Alignment".


0
 
LVL 2

Expert Comment

by:abesoft
Comment Utility
I would recommend that you DON't use the general approach that I suggested, but instead wrap your structs with

#pragma options -a2
struct blah{}
#pragma options -a.

Just so you can use system defined structures safely.  The -a. resets the original value (which will almost always be -a4.)
0
 
LVL 2

Expert Comment

by:abesoft
Comment Utility
Sorry.  Typo.  It should be #pragma option, not options.
0
 

Author Comment

by:borgz
Comment Utility
abesoft: thanks but we kinda did things differently - we
took the sizeofs of each field of the struct and converted the
binary file into the win32 platform.
jhance: thanks for the comment about the compiler switches. Too bad I wasn't able to actually use these comments.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now