From the MASM manual :
When a procedure is defined in one module and called in another module, it must be declared public in the defining module and external in the calling module(s). MASM treats EXTERNDEF as a public declaration in the defining module, and as an external declaration in the referencing module(s). As a result, a single include file can contain an EXTERNDEF declaration that works in both the defining module and any referencing module. It is ignored in modules that neither define nor reference the variable.
For example, let's say you have two source files "file1.asm" and "file2.asm". ;;;;;;;;;;; ; File1.asm ;;;;;;;;;;; .data var1 dword 0 Imagine you want to use var1 in "file2.asm". ;;;;;;;;;;;;; ; File2.asm ;;;;;;;;;;;;; .code mov var1, 0 It will not compile because the compiler doesn't know what var1 is. You have to declare var1 as "EXTERN" to inform the compiler that the variable is defined in another module. It also gives information about the type of the variable so the compiler can use it. Now the code is :


;;;;;;;;;;;;
; File2.asm
;;;;;;;;;;;;

EXTERN var1:dword

.code

mov  var1, 0

The next step is to link the two object files. The linker has to resolve the references in the object files. In file2.obj there is a reference to var1. The linker must find the definition of var1 somewhere or it will generate an "unresolved external" error. In order to find the definition of var1, you have to make it PUBLIC in "file1.asm". It tells the linker that it is ok to use this variable from another module. So now the files are :


;;;;;;;;;;;;;;
; File1.asm
;;;;;;;;;;;;;;;
  
PUBLIC var1:dword

.data 

var1 dword 0

;;;;;;;;;;;;;;
; File2.asm
;;;;;;;;;;;;;;;

EXTERN var1:dword

.code

mov    var1, 0

The EXTERNDEF is similar to EXTERN and PUBLIC. When you declare a variable with EXTERNDEF, the compiler will look in the source file to find the definition of the variable. There are 3 possibilities : - the variable is declared and defined in the source file -> it is made PUBLIC - the variable is not defined in the source file -> it is made EXTERN - the variable is not used in the source file -> the directive is ignored. Now the two source files are :


;;;;;;;;;;
; File1.asm
;;;;;;;;;;

EXTERNDEF var1:dword

.data

var1 dword 0   ; var1 is declared and defined, it is PUBLIC

;;;;;;;;;;
; File2.asm
;;;;;;;;;;

EXTERNDEF var1:dword

.code

mov var1, 0   ; var1 is declared and not defined, it is EXTERN

There is more info in the MASM manual. You can also read documentation about separate compilation. There is a good introduction in "Thinking in C++" by Bruce Eckel (search on the web, it's a free book) I hope it was clear (sorry it's not REAL english !)
Posted on 2001-05-12 02:42:00 by karim