declarations in include files: how do YOU feel?

Jim Vlcek vlcek at mit-caf.MIT.EDU
Sun May 14 10:11:51 AEST 1989


In article <181 at larry.sal.wisc.edu> jwp at larry.sal.wisc.edu.UUCP
(Jeffrey W Percival) writes: 

>what if the maintainer
>of the lib.a decides to re-implement an existing function as a macro,
>for example.  If the user has the thing appearing in an extern statement,
>it might break.  If the user relies on the lib.h file to "make everything
>OK", then the macro/function sleight of hand can proceed behind the scenes.

>Is that interpretation unflawed?

If what was once a function is turned into a macro, programs which
passed arguments with side effects to the function may not work
correctly with the macro.  You know the tune:

#define square(x) ((x)*(x))  /* Used to be a function ... needed speed */

y = square(++i);

Any macro->function sleight of hand had best not take place behind the
scenes, and in fact should probably not take place at all.  Going the
other direction is probably considered safe, although some programs
may have depended upon the side effects of the macro which is now a
function.  Probably anyone who does so deserves to suffer, though...

Jim Vlcek (vlcek at caf.mit.edu  uunet!mit-caf!vlcek)



More information about the Comp.lang.c mailing list