Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!nike!cad!faustus From: faustus@cad.BERKELEY.EDU (Wayne A. Christopher) Newsgroups: net.lang.c Subject: Re: What should be added to C Message-ID: <487@cad.BERKELEY.EDU> Date: Wed, 4-Jun-86 18:57:21 EDT Article-I.D.: cad.487 Posted: Wed Jun 4 18:57:21 1986 Date-Received: Thu, 5-Jun-86 20:32:52 EDT References: <1462@mmintl.UUCP> <5498@alice.uUCp> <1497@mmintl.UUCP> <1518@mmintl.UUCP> Organization: CAD Group, U.C. Berkeley Lines: 43 In article <1518@mmintl.UUCP>, franka@mmintl.UUCP (Frank Adams) writes: > This doesn't let you use "#if" in the body of the macro, as my example would > require. To fully explicate, my example would be: > > #begdef copy(to, from, number) > #if sizeof(from) % WORD_SIZE == 0 > copyword(to, from, number * sizeof(from) / WORD_SIZE) > #else > strncpy(to, from, number * sizeof(from)) > #endif > #enddef You can't use sizeof in a #if anyway. You can only use constants and pre-defined cpp symbols. (Pardon me if you're talking about a different compiler -- I'm using 4.3 cc.) It is not clear what you are trying to do with your macro anyway. Is 'from' always a char *? If so you don't need the sizeof. Can it be a pointer to anything? In that case you don't want to use strncpy, and you would want to write sizeof (*from), if it worked. In most of the cases where you want to do something like this, you can put the #if's outside of the #define's anyway, and if you can't, the macro is probably complex enough to make into a function. > >It's also an extra character to type. If you are prone to this sort of > >error, just run your code through grep if | grep = | grep -v == ... > > Thanks but no thanks. If one added a separate step to the compilation > process for each type of relatively common error, nothing would ever get > done. Again, please note that I did not propose outlawing "=" as a > default -- you would have to specify an option to exclude it. I meant that suggestion as a sort of "cleaning up a several months' worth of code and finding little bugs" device. I would say that in the normal process of finding bugs you will locate = / == problems pretty quickly, and after you use the language for a while you just learn not to do things like that. I personally think that := is sort of ugly anyway... If you really want a lot of extra checking, soup up lint a bit... You don't have to get your own private lint through any standards committees... Wayne