www.digitalmars.com         C & C++   DMDScript  

c++ - Compatibility with other C++ dev systems

reply John Kohr <jjkohr1 home.com> writes:
Since I just discovered that Digital Mars compiler existed (I thought
Symantec killed the C++ project after version 7.5) I would like to say a
big thanks to Walter for putting time and effort to update this
wonderful tool!

Could you please fix the following inline assembler bug to make it more
compatible with MASM, TASM, CodeWarrior and other assemblers and C/C++
compilers:

The following statement is legal with most other dev systems:

dd    offset any_variable_or_label

where any_variable_or_label is, of course, any variable or label.
Digitalmars chokes with the error "expression expected".

This is actually really very simple and should not take more than a few
minutes to fix, having the source code. If you are wondering what the
assembled 4 bytes should look like, consider the following statement:

mov    eax, offset any_variable_or_label

which assembles as:

B8 xx xx xx xx

where xx xx xx xx represents the linker relocatable address of the
variable or label. So just take out the B8 and you get what the
assembled 4 bytes should be.

The DD statement used this way works with all other systems I tried and
has many important uses, most notably in optimizing C/C++ switch
statements. As a matter of fact, many C/C++ compilers use the technique
extensively.

Thanks,

John
Jun 07 2001
parent reply "Walter" <walter digitalmars.com> writes:
That is a great suggestion. -Walter

John Kohr wrote in message <3B1FFA4B.C8E2BB8E home.com>...
Since I just discovered that Digital Mars compiler existed (I thought
Symantec killed the C++ project after version 7.5) I would like to say a
big thanks to Walter for putting time and effort to update this
wonderful tool!

Could you please fix the following inline assembler bug to make it more
compatible with MASM, TASM, CodeWarrior and other assemblers and C/C++
compilers:

The following statement is legal with most other dev systems:

dd    offset any_variable_or_label

where any_variable_or_label is, of course, any variable or label.
Digitalmars chokes with the error "expression expected".

This is actually really very simple and should not take more than a few
minutes to fix, having the source code. If you are wondering what the
assembled 4 bytes should look like, consider the following statement:

mov    eax, offset any_variable_or_label

which assembles as:

B8 xx xx xx xx

where xx xx xx xx represents the linker relocatable address of the
variable or label. So just take out the B8 and you get what the
assembled 4 bytes should be.

The DD statement used this way works with all other systems I tried and
has many important uses, most notably in optimizing C/C++ switch
statements. As a matter of fact, many C/C++ compilers use the technique
extensively.

Thanks,

John

Jun 08 2001
parent reply John Kohr <jjkohr1 home.com> writes:
It seems that you thought of this yourself long ago since I discovered the
undocumented/half-implemented DA assembler directive early on in the 8.x
compiler series.

I assume it means Define Address and will work eventually just like what I
suggested for DB, DW, DD, DQ, DT in my post except that it won't need the
OFFSET keyword. That could save some typing and would even be portable
across various compilers which do not support it with the following simple
#define:

#define DA     DD offset

But maybe you meant it for something else, like Difference of Address
between 2 code labels. That would also make sense since the difference of
any two relocatable addressess in the same executable is actually a constant
integer, independent of where in memory the operating system loads the file
and independent of any relocations that are thus applied!


Keep up the good work!

Thanks,

John

PS: Questions of the curious:

Q1: Why does the _TEXT section emitted by DigitalMars compiler start with 16
unused zero bytes?

Q2: Is there a structure to the .CRT$XIA section or is it unstructured?


Walter wrote:

 That is a great suggestion. -Walter

 John Kohr wrote in message <3B1FFA4B.C8E2BB8E home.com>...
Since I just discovered that Digital Mars compiler existed (I thought
Symantec killed the C++ project after version 7.5) I would like to say a
big thanks to Walter for putting time and effort to update this
wonderful tool!

Could you please fix the following inline assembler bug to make it more
compatible with MASM, TASM, CodeWarrior and other assemblers and C/C++
compilers:

The following statement is legal with most other dev systems:

dd    offset any_variable_or_label

where any_variable_or_label is, of course, any variable or label.
Digitalmars chokes with the error "expression expected".

This is actually really very simple and should not take more than a few
minutes to fix, having the source code. If you are wondering what the
assembled 4 bytes should look like, consider the following statement:

mov    eax, offset any_variable_or_label

which assembles as:

B8 xx xx xx xx

where xx xx xx xx represents the linker relocatable address of the
variable or label. So just take out the B8 and you get what the
assembled 4 bytes should be.

The DD statement used this way works with all other systems I tried and
has many important uses, most notably in optimizing C/C++ switch
statements. As a matter of fact, many C/C++ compilers use the technique
extensively.

Thanks,

John


Jun 11 2001
parent "Walter" <walter digitalmars.com> writes:
DA is supposed to be "Define Address" and be usable for labels and such. It
isn't documented because, as you say, it is only half implemented. I need to
get it fixed.

The 16 bytes of 0 is one of the Great DOS Mysteries, as in I could never
figure out why Microsoft DOS required it to be there. So the linker always
adds it.

.CRT$XIA is in \dm\src\core32\cinit.asm, and is simply a null terminated
array of function pointers to static constructors that gets called by the
startup code.


John Kohr wrote in message <3B25711F.3C6B1EEF home.com>...
It seems that you thought of this yourself long ago since I discovered the
undocumented/half-implemented DA assembler directive early on in the 8.x
compiler series.

I assume it means Define Address and will work eventually just like what I
suggested for DB, DW, DD, DQ, DT in my post except that it won't need the
OFFSET keyword. That could save some typing and would even be portable
across various compilers which do not support it with the following simple
#define:

#define DA     DD offset

But maybe you meant it for something else, like Difference of Address
between 2 code labels. That would also make sense since the difference of
any two relocatable addressess in the same executable is actually a

integer, independent of where in memory the operating system loads the file
and independent of any relocations that are thus applied!


Keep up the good work!

Thanks,

John

PS: Questions of the curious:

Q1: Why does the _TEXT section emitted by DigitalMars compiler start with

unused zero bytes?

Q2: Is there a structure to the .CRT$XIA section or is it unstructured?


Walter wrote:

 That is a great suggestion. -Walter

 John Kohr wrote in message <3B1FFA4B.C8E2BB8E home.com>...
Since I just discovered that Digital Mars compiler existed (I thought
Symantec killed the C++ project after version 7.5) I would like to say a
big thanks to Walter for putting time and effort to update this
wonderful tool!

Could you please fix the following inline assembler bug to make it more
compatible with MASM, TASM, CodeWarrior and other assemblers and C/C++
compilers:

The following statement is legal with most other dev systems:

dd    offset any_variable_or_label

where any_variable_or_label is, of course, any variable or label.
Digitalmars chokes with the error "expression expected".

This is actually really very simple and should not take more than a few
minutes to fix, having the source code. If you are wondering what the
assembled 4 bytes should look like, consider the following statement:

mov    eax, offset any_variable_or_label

which assembles as:

B8 xx xx xx xx

where xx xx xx xx represents the linker relocatable address of the
variable or label. So just take out the B8 and you get what the
assembled 4 bytes should be.

The DD statement used this way works with all other systems I tried and
has many important uses, most notably in optimizing C/C++ switch
statements. As a matter of fact, many C/C++ compilers use the technique
extensively.

Thanks,

John



Jun 11 2001