Path: utzoo!attcan!uunet!ncrlnk!ncrcae!ece-csc!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: gurulet aptitude test (and bug) Message-ID: <2416@xyzzy.UUCP> Date: 16 Dec 88 17:07:43 GMT Organization: Data General, RTP NC. Lines: 52 Referenes: <228@celerity.UUCP> > jpa@celerity.UUCP (Jeff Anderson) > I submit it only as an interesting puzzle > [... example appended to end of article for reference ...] It's more than that. It shows a place where lint gives a misleading-at-best diagnostic. In particular, lint says sub2: variable # of args. t1.c(19) :: t1.c(16) sub1: variable # of args. t1.c(13) :: t1.c(27) sub1 value is used, but none returned sub2 returns value which is always ignored The oddity is "sub1 value is used, but none is returned". The value isn't, in fact, used. But apparently many compilers generate code which fails if a function declared to return a struct does not do so. This problem would be much less probable if one always declared one's function types explicitly. And paid attention to what lint tells one, of course. /***************************************************\ * * * What is wrong with this program? This is a test. * * * \***************************************************/ struct zztop { int a; int b; } /* main calls sub1 which calls sub2 */ #define UGLY 0x77777777 sub1() { struct zztop zz; zz.a = UGLY; sub2(zz); } sub2() { struct zztop zz; zz.b = UGLY; return(UGLY); } main() { struct zztop zz; sub1(&zz); } -- The real problem is not whether machines think, but whether men do. --- B.F. Skinner -- Wayne Throop !mcnc!rti!xyzzy!throopw