Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!rozin From: rozin@unix.cis.pitt.edu (R Rozin) Newsgroups: comp.lang.c++ Subject: Bug in Zortech C++ 2.0 Keywords: typedef structs, unions Message-ID: <22379@unix.cis.pitt.edu> Date: 16 Feb 90 17:06:04 GMT Organization: Univ. of Pittsburgh, Computing & Information Services Lines: 102 It seems that Zortech C++ 2.0 has a bug in the way it mangles names relating to typedef'd structs and typedef'd unions. Consider the following code (3 files): /*---- u2.h ---*/ typedef union { int b; char c; } U2 ; void f(U2 *); /*--- u2.c ---*/ #include "u2.h" void f(U2 *a) { return ; } /*--- main.c ---*/ typedef union { int a; char b; } U1 ; #include "u2.h" main() { U2 u; f(&u); } /*--------------------------------*/ The problem occurs during linkage, as it cannot find the function f (in main.c) due to the mangled versions of f in u2.c and main.c. It looks as if typedef'd unions (and structs) are numbered sequentially so that order of #inclusion (or lack of it) matters! In other words, in u2.c the only typedef'd union is U2, while in main.c we have U1 and U2 as unions. Thus f in main.c gets mangled to _f__Np3_C2 and f in u2.c gets mangled to _f__Np3_C1 and the linker croaks. (It seems that the _C2 in the mangled name for main.c indicates that it is the second typedef'd union encountered, while the _C1 for u2.c indicates that it is the first union encountered.) The following output is generated by the ztc command (in verbose mode): C:\>ztc -cpp -v main.c u2.c ZTCPP1 -v -otemp.tmp main.c ZTCPP1 2.06 Copyright (C) 1985-1989 by Zortech, written by Walter Bright main ZTCPP1 complete. Time: 0.39 seconds ZTC2 -v temp.tmp -omain ZTC2 2.05 Copyright (C) 1985-1989 by Zortech, written by Walter Bright main ZTC2 complete. Code: 0x0011 (17) Data: 0x0000 (0) Time: 0.44 seconds ZTCPP1 -v -otemp.tmp u2.c ZTCPP1 2.06 Copyright (C) 1985-1989 by Zortech, written by Walter Bright f ZTCPP1 complete. Time: 0.33 seconds ZTC2 -v temp.tmp -ou2 ZTC2 2.05 Copyright (C) 1985-1989 by Zortech, written by Walter Bright f__Np3_C1 ZTC2 complete. Code: 0x000a (10) Data: 0x0000 (0) Time: 0.49 seconds BLINK main+u2/noi; BLINK 4.02 Copyright (c) 1986-89 by Zortech, written by Bjorn N. Freeman-Benson Error: undefined symbols: _f__Np3_C2 in main.c (main.OBJ) BLINK complete. Time: 1.70 seconds --- errorlevel 1 /*-----------------------------------------*/ The workaround is obviously to declare a typedef'd union before U2 in u2.c so that the number of typedef'd unions will be the same (and the unions of import must be in the same position) in the different files for the compilation to proceed. Yuck! --Roman -- Roman Rozin rozin@cs.pitt.edu Graduate Student rozin@PITTVMS.BITNET University of Pittsburgh