Prepending _ in C external names necessary?
Thomas H{meenaho
thomas at kuling.UUCP
Thu Nov 21 16:08:40 AEST 1985
In article <1232 at hpda.UUCP> davel at hpda.UUCP (Dave Lennert) writes:
>We're considering changing our C compiler to *not* prepend an underscore
>at the beginning of all external names (functions, variables). Will this
>break things? Are there reasons (technical/religious) that we should not
>do this?
I say don't do it!
In one particular C compiler I've seen one can produce perefectly good
C code that doesn't work when compiled!
Consider the following small example from a 68K machine running V7:
main(){
extern long a7; /* perfectly legal declaration */
a7 = 0x1234;
}
As the variable a7 is declared as external the compiler doesn't allocate
any space for it but assumes it will be defined at link time.
If I compile this into assembler the resulting code looks something
like this:
main:
link a6,#0
move.l #0x1234,a7
unlk a6
rts
As a7 is the stackpointer on a 68K the result will be at best unpredictable
with another program! Needless to say the behaviour is the same for any
legal register name.
--
Thomas Hameenaho, Dept. of Computer Science, Uppsala University, Sweden
Phone: +46 18 138650
UUCP: thomas at kuling.UUCP (...!{seismo,mcvax}!enea!kuling!thomas)
More information about the Comp.lang.c
mailing list