What should be added to C

Wayne A. Christopher faustus at cad.BERKELEY.EDU
Thu Jun 5 08:57:21 AEST 1986


In article <1518 at mmintl.UUCP>, franka at 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



More information about the Comp.lang.c mailing list