Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker!ira.uka.de!smurf!nadia!ananke!kaiser From: kaiser@ananke.stgt.sub.org (Andreas Kaiser) Newsgroups: comp.lang.c Subject: Handling of untagged structures by the C compiler Message-ID: <14.26FB1164@ananke.stgt.sub.org> Date: 22 Sep 90 07:08:05 GMT Organization: Ananke, Stuttgart, FRG Lines: 33 In a message of , Vox Populi ) (ravim@gtenmc.UUCP (Ravi K Mandava ) writes: VP)> 4 #define ST struct { int i; } VP)> 8 ST *a; VP)> 12 if ((a = (ST *)malloc(sizeof(ST))) == NULL) VP)> It appears that for every untagged structure declaration/typecast, the VP)> compiler generates a unique tag internally and does not bother to VP)> check for equivalence of the previously encountered structures. According to ANSI, two structures are only compatible, if they have the same "tagged type". Two identically declared structures are incompatible. VP)> [As for myself, I always try to use typedefs or tags for structures. VP)> I happened to come across this problem while bug-fixing someone VP)> else's code. So please no chidings for writing bad code :-) ] VP)> Or is it that this limitation is only with this particular compiler? Some very old C compilers (the original Ritchie compiler for PDP-11) do not care about structure types at all. It was possible to write code like this (found in UNIX Version 6): register int i; struct { char high, low; }; .... i.high .... -- :::::::::::::::::::: Internet: kaiser@ananke.stgt.sub.org :: Andreas Kaiser :: Fidonet: 2:507/18.7206 (+ 2:509/5.2512) ::::::::::::::::::::