Board index » cppbuilder » Improper use of typedef

Improper use of typedef


2005-11-02 03:06:36 AM
cppbuilder18
I am adding a feature to a product and have hit a snag. I have source code
for a feature developed using the Microsoft compiler. The code uses
assembly code during interrupts to manipulate pointers and settings of a
linked structure. I want to avoid translating the assembly back into C.
The code uses indirect references and does not currently compile with BC5.
Here is a test sample:
void test()
{
typedef struct TestStruct
{
int a;
int b;
} TestType;
TestType* testPtr;
__asm {
push ds
lds bx,testPtr
lea di,[bx]TestType.b
}
}
Console compilation output:
MAKE Version 5.0 Copyright (c) 1987, 1997 Borland International
C:\BC5\BIN\BCC @MAKE0044.@@@ test.cpp
Borland C++ 5.2 Copyright (c) 1987, 1997 Borland International
Mar 19 1997 17:29:40
test.cpp:
Error test.cpp 14: Improper use of typedef 'TestType' in function test()
I have also tried these additional indirrect reference syntax without
success:
lea di,bx[TestType.b]
lea di,[(TestType bx).b]
lea di,[bx + TestType.b]
mov [bx + TestType.b],al
--Blaze
 
 

Re:Improper use of typedef

Robert Blazewicz wrote:
Quote
I want to avoid translating the assembly back into C.
The code uses indirect references and does not currently compile with BC5.
Are you compiling this as a 16bit application?
The asm is for 16bit code
Quote
typedef struct TestStruct
{
int a;
int b;
} TestType;

TestType* testPtr;
Try it as a far pointer.
TestType far* testPtr;
Quote
__asm {
push ds
lds bx,testPtr
lea di,[bx]TestType.b
My asm has gotten rusty, and I don't think I ever used typedef in this
way.
You might try it with TestStruct.b
Or perhaps without the struct preface?
lea di,[bx]b
Or
lea di,[bx+offset b]
Or
lea di,[bx+offset TestStruct.b]
Or
lea di,[bx+offset testPtr->b]
But I think it might be better as
_DI = &testPtr->b;
Or
_DI = &((TestType*)_BX)->b;
Of course, in this case, you could use lea di,[bx+2]
but that defeats the purpose of the struct.
 

Re:Improper use of typedef

Thanks Bob,
Yes this is for a 16-bit DOS application that runs in a 386sx embedded
system.
I tried your suggestions and some other variants. The only variant I found
that compiles, other than manually proving the offset, is to reference an
instance of the structure:
void test()
{
typedef struct TestStruct
{
int a;
int b;
} TestType;
TestType testValue; // Ack, used for assembly offset
TestType* testPtr;
__asm {
push ds
lds bx,testPtr
lea di,[bx+testValue.b]
}
}
I have no idea yet if this compiles to what I need ;-/
--Blaze
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
Robert Blazewicz wrote:

>I want to avoid translating the assembly back into C.
>The code uses indirect references and does not currently compile with BC5.

Are you compiling this as a 16bit application?
The asm is for 16bit code

>typedef struct TestStruct
>{
>int a;
>int b;
>} TestType;
>
>TestType* testPtr;

Try it as a far pointer.
TestType far* testPtr;

>__asm {
>push ds
>lds bx,testPtr
>lea di,[bx]TestType.b

My asm has gotten rusty, and I don't think I ever used typedef in this
way.
You might try it with TestStruct.b
Or perhaps without the struct preface?
lea di,[bx]b
Or
lea di,[bx+offset b]
Or
lea di,[bx+offset TestStruct.b]
Or
lea di,[bx+offset testPtr->b]

But I think it might be better as
_DI = &testPtr->b;
Or
_DI = &((TestType*)_BX)->b;

Of course, in this case, you could use lea di,[bx+2]
but that defeats the purpose of the struct.


 

{smallsort}