Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!rochester!kodak!sisd!jeh From: jeh@sisd.kodak.com (Ed Hanway) Newsgroups: comp.sys.amiga.tech Subject: Re: C compilers code generation Message-ID: <1990Nov21.131206.2634@sisd.kodak.com> Date: 21 Nov 90 13:12:06 GMT References: <1990Nov19.130657.19380@sisd.kodak.com> <90324.204949GIAMPAL@auvm.auvm.edu> Sender: news@sisd.kodak.com Organization: Printer Products Division Eastman Kodak Lines: 25 GIAMPAL@auvm.auvm.edu writes: >In article <1990Nov19.130657.19380@sisd.kodak.com>, jeh@sisd.kodak.com (Ed >Hanway) says: >>#define SAY(s) Write(backstdout, s, strlen(s)) >#define MSG(s) { char *s; Write(Output(), s, strlen(s)); } > >This way you only get one copy of the string constant, and you get a nice >function. I guess you really mean #define MSG(s) { char *tmp = s; Write(whatever, tmp, strlen(tmp)); } which is fine, but my version was posted as an example of when a builtin version of strlen() came in handy. In Lattice (now SAS) C, strlen("constant") is evaluated at compile time, so, using my version, SAY("foo") would compile as Write(backstdout, "foo", 3). This not only eliminates the extra copy of the string constant, it eliminates the strlen() operation altogether. -- Ed Hanway --- uunet!sisd!jeh This message is packed as full as practicable by modern automated equipment. Contents may settle during shipment.