Wireshark-dev: Re: [Wireshark-dev] Replace ntohl() with g_ntohl() -> automated check?
From: Ulf Lamping <[email protected]>
Date: Sat, 11 Nov 2006 05:51:20 +0100
Thomas Anders wrote:
Joerg Mayer wrote:
On Tue, Nov 07, 2006 at 12:57:59PM +0000, LEGO wrote:
what about #defining them so they trigger an error?
#define ntohl error() won't work, a g_ntohl would match as well.
I'm not sure that's true. Have you actually tried?
a macro definition is different from a simple define, #define ntohl() will *not* affect any g_ntohl() calls! -> no problem here!
FWIW, Samba3 is doing something similar for C++ reserved words:

- --- snip ---
/* only do the C++ reserved word check when we compile
   to include --with-developer since too many systems
   still have comflicts with their header files (e.g. IRIX 6.4) */

#if !defined(__cplusplus) && defined(DEVELOPER)
#define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
- --- snap ---

This is a simple approach which seem to be also working for function declarations :-)
If I add:

#define printf() #error "don't to this!"

below any other #include's the file won't compile if some printf calls are in the code - exactly what we need to avoid.
Unfortunately it won't show the error text, but at least we get an error 
while compiling, which is much better than what we have today.
My observations were done on MSVC, but I would guess this should work on 
other compilers/platforms as well.

I would like to add the checks to some common include file (e.g. proto.h) so all existing dissectors will be forced to remove the "offending" calls.
However, you'll get into trouble if the #define printf is done before 
the inclusion of the corresponding <stdio.h>.
The drawback on this: You need a sequence of include files for this to 
work (in all WS files that includes proto.h!), having e.g. stdio.h 
included before proto.h.
The sequence which would make most sense:
- config.h
- system include files <stdio.h>
- library include files <glib.h>
- WS internal library include files <epan/...h>, <ftypes/...h>, ...
- "local" include files

But even worse, some include files do #include on their own, making the outlined include sequence above very difficult.
So with the current #include sequence this won't work!

Any ideas?

Regards, ULFL