On 08/22/2012 05:05 AM, Marc Espie wrote:
On Tue, Aug 21, 2012 at 09:43:25PM +0200, Alexandre Ratchov wrote:
On Mon, Aug 20, 2012 at 10:10:39AM +0200, Marc Espie wrote:
- prototypes for everything.
Why, aren't forward declaration good enough ?
Not with -Wstrict-prototypes.
But does this mean we start avoiding local variables that shadow
functions? This means that div, pause, time, and many other common
names are to be avoided as well, doesn't it?
Well, if you write portable code, you should.
Some of this may be implemented as macros under some OSes ;(
I don't have the C standard with me, but I believe that it doesn't restrict
very much about this. The only thing I remember for sure is that, unless
specifically documented differently, functions in the standard must exist
as functions. They may also exist as macros, and you may have to do
something like:
#undef function
in order to get a pointer to said function...
Some people (myself included) require that no local name shadow any global.
There are many such requirements - for example, all structure members
are unique
across all structures, all function names are unique across all modules,
source format rules, etc.
which prevent accidental misuse, therefore decreasing hard-to-find bugs.
Compilers may enforce some of these. Depending on the compiler to find
all of your accidental problems is not wise. Depending on your brain to
remember every detail of every module to prevent accidents is not wise
at all.
Granted, the trend seems to be that everything excepts BSDs and Linux is
dead anyways, so if it builds there, you should be fine. ;(
C is still alive in the embedded world.
Many of these considerations are still valid in C++ which has wider use,
unfortunately.
Geoff Steckel