accessing external global variables with masm

Started by a_h, July 14, 2005, 06:08:31 PM

Previous topic - Next topic

a_h

Hi!

I'm sorry that I double post (similar posting in the campus), but I think it's better suited here for the people to read it that might know an answer.

Currently I've some masm-assembly as .asm file that is part of a tiny Visualc++6-project. In the .cpp file I declare global variables N, B of type unsigned int that I want to access:

However
---------------------------------
.686
.model flat, stdcall
option casemap :none

Extern _B:DWORD
Extern _N:DWORD

.code
...
--------------------------------
doesn't link. It doesn't work with and without the leading underscores and neither with 'C' instead of stdcall.

How can I access them?

Thanks a lot for your reply! Hannes

hutch--

Hannes,

MASM has the correct notation to read an external value with EXTERNDEF but you will have to read up on the VC compiler to find the method of making a global variable visible. In MASM you use PUBLIC and this may be a hint of what to do in VC.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

tenkey

In your .cpp file declare your variables with extern "C". Make sure you have the correct case, as the default for linking C++ code is case-sensitive names.

extern "C" unsigned int N, B;

As a further check, look at the linker error messages, as they will tell you what names the C++ compiler created for linking purposes.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

Vortex

Thanks tenkey, extern "C" is the main trick :U