Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!hsi!genly!chris From: chris@genly.UUCP (Chris Hind Genly) Newsgroups: comp.sys.amiga Subject: Re: Lattice/SAS C 5.10 HERE! Message-ID: Date: 24 Aug 90 20:50:11 GMT References: <14874@shlump.nac.dec.com> Lines: 117 >In article <1990Aug23.052447.24545@zorch.SF-Bay.ORG>, xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) writes... >So tell me, does it still do a no-warning, no guru, stone cold system >crash, trashing Rad:, if you try to do/use a 30 line #define? >In article <14874@shlump.nac.dec.com> barrett@meridn.enet.dec.com (Keith Barrett) writes: >Standard C coding practice recommends that a define should fit in 1 line >of 80 characters; I think you got what you deserved. You're not the type >to sue a ladder company because the instructions did not state "don't >place the ladder in mud" and you did and fell, are you? :-) I see the smiley, but I assume it only applies to the preceding sentence, not the whole paragraph. First I have to object to "you got what you deserved." A compiler should not crash when it runs into a limitation. This is clearly a bug and should be fixed. Second, Multi-line macros are legitimate in C. I use them all the time. As an example of a useful multi-line macro see the code below. Macros are wonderful because they let you "escape from the language". C does not directly support iteration abstraction. With macros I can write my own. C does not support inlining. With macros I can do my own inlining. In each case the macros are usually longer than one line. ==================================================================== /* * File iterators * * 8/25/90 Chris Hind Genly chris@genly.uucp * * No rights reserved. * */ #ifndef file_h #define file_h #ifndef stdin #include #endif #include #include /* * Iterate through all files in a directory. * * The user declares dir as either a character pointer or character array. * It should be set to a directory path string. * The macro declares fi, and path. Fi is the Amiga file info block. * Path is a char array containing the path to a file in the dir. * Fi and path may be referenced in the body of the for. * Break and continue are permitted inside this iterator. * * Example: * * FOR_ALL_FILES("c:", fi, path) { * printf("%s: %d\n", path, fi->fib_Size); * } END_FOR_ALL_FILES; */ #define FOR_ALL_FILES(dir, fi, path) \ { \ BPTR lock; \ static struct FileInfoBlock fis, *fi=&fis; \ int ok; \ char path[200], *sep; \ \ switch(dir[strlen(dir)-1]) { \ case '/': case ':': sep = ""; break; \ default: sep = "/"; break; \ } \ \ lock = Lock(dir, ACCESS_READ); \ if (lock == 0) { \ fprintf(stderr, "snews: unable to lock %s\n", dir); \ exit(1); \ } \ \ ok = Examine(lock, fi); \ while(ok = ExNext(lock, fi)) { \ strcpy(path, dir); \ strcat(path, sep); \ strcat(path, fi->fib_FileName); #define END_FOR_ALL_FILES \ } \ \ UnLock(lock); \ } /* * Iterate through all directories of a directory. * * Same as above, except the body is only executed for directories. */ #define FOR_ALL_DIRS(dir, fi, path) \ FOR_ALL_FILES(dir, fi, path) \ if (fi->fib_DirEntryType <= 0) continue; #define END_FOR_ALL_DIRS \ END_FOR_ALL_FILES #endif ==================================================================== * * * \|/ * _______ --O-- ____/ KC1VP \____ * /|\ * _____________/ (203) 389-8680 \_______________ ______/ 95 Fountain Terr., New Haven, CT, USA, 06515 \_______ / Chris Hind Genly chris@genly.uucp uunet!hsi!genly!chris \ ----------------------------------------------------------------